From dc2193456b7d7ef5da6b696c3792e056691b9335 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Sat, 6 Oct 2012 11:49:22 -0700 Subject: [PATCH 1/7] Initial commit --- .gitignore | 6 ++++++ README.md | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 .gitignore create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f182a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.class + +# Package Files # +*.jar +*.war +*.ear diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc96d37 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +BukkitTelnetClient +================== + +BukkitTelnetClient is a very, very basic telnet client for use with the BukkitTelnet CraftBukkit plugin. \ No newline at end of file From 12c5e384ae4f84666284bc851d115edd3b5775ae Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Sat, 6 Oct 2012 14:56:19 -0400 Subject: [PATCH 2/7] v1.0.0.0 - Initial Commit --- .gitignore | 4 + build.xml | 74 ++ manifest.mf | 3 + nbproject/build-impl.xml | 1053 +++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/project.properties | 75 ++ nbproject/project.xml | 15 + .../BTC_ConnectionManager.java | 155 +++ .../BukkitTelnetClient.form | 154 +++ .../BukkitTelnetClient.java | 326 +++++ 10 files changed, 1867 insertions(+) create mode 100644 build.xml create mode 100644 manifest.mf create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java create mode 100644 src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form create mode 100644 src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java diff --git a/.gitignore b/.gitignore index 0f182a0..66dd0c3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ *.jar *.war *.ear + +/nbproject/private/ +/build/ +/dist/ diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..fcbdbd9 --- /dev/null +++ b/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project BukkitTelnetClient. + + + diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..408044f --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1053 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..267d65b --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b147f9b6 +build.xml.script.CRC32=71290436 +build.xml.stylesheet.CRC32=28e38971@1.50.2.46 +# 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. +nbproject/build-impl.xml.data.CRC32=b147f9b6 +nbproject/build-impl.xml.script.CRC32=8a821c88 +nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.2.46 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..378deae --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,75 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=BukkitTelnetClient +application.vendor=Steven +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/BukkitTelnetClient.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${libs.Apache_Commons_Lang.classpath}:\ + ${libs.Apache_Commons_Net.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=me.StevenLawson.BukkitTelnetClient.BukkitTelnetClient +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..08ad5eb --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + BukkitTelnetClient + + + + + + + + + diff --git a/src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java b/src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java new file mode 100644 index 0000000..9d8ba57 --- /dev/null +++ b/src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java @@ -0,0 +1,155 @@ +package me.StevenLawson.BukkitTelnetClient; + +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.net.telnet.TelnetClient; + +public class BTC_ConnectionManager +{ + private static final Logger log = Logger.getLogger("BukkitTelnetClient"); + private final BukkitTelnetClient btc; + private final TelnetClient tc; + private Thread connectThread; + private String hostname; + private int port; + private boolean can_do_disconnect = false; + + public BTC_ConnectionManager(BukkitTelnetClient btc) + { + this.btc = btc; + this.tc = new TelnetClient(); + } + + public void trigger_connect(String hostname, int port) + { + btc.getBtn_connect().setEnabled(false); + btc.getTxt_server().setEnabled(false); + btc.getBtn_disconnect().setEnabled(true); + + System.out.println("Connecting to " + hostname + ":" + port + "..."); + + this.hostname = hostname; + this.port = port; + + startConnectThread(); + } + + public void trigger_connect(String hostname_and_port) + { + String[] parts = StringUtils.split(hostname_and_port, ":"); + + if (parts.length <= 1) + { + this.trigger_connect(parts[0], 23); + } + else + { + int t_port = 23; + + try + { + t_port = Integer.parseInt(parts[1]); + } + catch (NumberFormatException ex) + { + } + + this.trigger_connect(parts[0], t_port); + } + } + + public void trigger_disconnect() + { + if (can_do_disconnect) + { + can_do_disconnect = false; + + try + { + tc.disconnect(); + } + catch (IOException ex) + { + log.log(Level.SEVERE, null, ex); + } + } + } + + public void finish_disconnect() + { + btc.getBtn_connect().setEnabled(true); + btc.getTxt_server().setEnabled(true); + btc.getBtn_disconnect().setEnabled(false); + btc.getBtn_send().setEnabled(false); + btc.getTxt_command().setEnabled(false); + + System.out.println("\nDisconnected."); + } + + public void send_command(String text) + { + try + { + System.out.println(text); + tc.getOutputStream().write((text + "\n").getBytes()); + tc.getOutputStream().flush(); + } + catch (IOException ex) + { + log.log(Level.SEVERE, null, ex); + } + } + + private void startConnectThread() + { + if (connectThread != null) + { + return; + } + + connectThread = new Thread(new Runnable() + { + @Override + public void run() + { + try + { + tc.connect(hostname, port); + can_do_disconnect = true; + + btc.getBtn_send().setEnabled(true); + btc.getTxt_command().setEnabled(true); + btc.getTxt_command().requestFocusInWindow(); + + InputStream in = tc.getInputStream(); + + byte[] buffer = new byte[1]; + int ret_read = 0; + do + { + ret_read = in.read(buffer); + if (ret_read > 0) + { + System.out.print(new String(buffer, 0, ret_read)); + } + } + while (ret_read >= 0); + + trigger_disconnect(); + } + catch (Exception ex) + { + log.log(Level.SEVERE, null, ex); + } + + finish_disconnect(); + + connectThread = null; + } + }); + connectThread.start(); + } +} diff --git a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form new file mode 100644 index 0000000..c7b9753 --- /dev/null +++ b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form @@ -0,0 +1,154 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java new file mode 100644 index 0000000..e1bd115 --- /dev/null +++ b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java @@ -0,0 +1,326 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package me.StevenLawson.BukkitTelnetClient; + +import java.awt.event.KeyEvent; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import javax.swing.SwingUtilities; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; + +/** + + @author + Steven + */ +public class BukkitTelnetClient extends javax.swing.JFrame +{ + private BTC_ConnectionManager connection_mgr; + + public BukkitTelnetClient() + { + initComponents(); + redirectSystemStreams(); + connection_mgr = new BTC_ConnectionManager(this); + } + + private void updateTextPane(final String text) + { + SwingUtilities.invokeLater(new Runnable() + { + @Override + public void run() + { + Document doc = main_output.getDocument(); + try + { + doc.insertString(doc.getLength(), text, null); + } + catch (BadLocationException e) + { + throw new RuntimeException(e); + } + main_output.setCaretPosition(doc.getLength() - 1); + } + }); + } + + private void redirectSystemStreams() + { + OutputStream out = new OutputStream() + { + @Override + public void write(final int b) throws IOException + { + updateTextPane(String.valueOf((char) b)); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException + { + updateTextPane(new String(b, off, len)); + } + + @Override + public void write(byte[] b) throws IOException + { + write(b, 0, b.length); + } + }; + + System.setOut(new PrintStream(out, true)); + System.setErr(new PrintStream(out, true)); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + main_output = new javax.swing.JTextPane(); + txt_command = new javax.swing.JTextField(); + btn_connect = new javax.swing.JButton(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + txt_server = new javax.swing.JTextField(); + btn_disconnect = new javax.swing.JButton(); + btn_send = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("BukkitTelnetClient"); + + main_output.setEditable(false); + main_output.setFont(new java.awt.Font("Courier New", 0, 12)); // NOI18N + jScrollPane1.setViewportView(main_output); + + txt_command.setEnabled(false); + txt_command.addKeyListener(new java.awt.event.KeyAdapter() { + public void keyPressed(java.awt.event.KeyEvent evt) { + txt_commandKeyPressed(evt); + } + }); + + btn_connect.setText("Connect"); + btn_connect.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + btn_connectMouseClicked(evt); + } + }); + + jLabel1.setText("Command:"); + + jLabel2.setText("Server:"); + + txt_server.setText("tf.madgeekonline.com:28995"); + txt_server.addKeyListener(new java.awt.event.KeyAdapter() { + public void keyPressed(java.awt.event.KeyEvent evt) { + txt_serverKeyPressed(evt); + } + }); + + btn_disconnect.setText("Disconnect"); + btn_disconnect.setEnabled(false); + btn_disconnect.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + btn_disconnectMouseClicked(evt); + } + }); + + btn_send.setText("Send"); + btn_send.setEnabled(false); + btn_send.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + btn_sendMouseClicked(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jLabel2, 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)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(18, 18, 18) + .addComponent(txt_command)) + .addGroup(layout.createSequentialGroup() + .addGap(17, 17, 17) + .addComponent(txt_server, javax.swing.GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(btn_connect) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btn_disconnect)) + .addComponent(btn_send, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) + .addContainerGap()) + ); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btn_connect, btn_disconnect}); + + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .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(jLabel1) + .addComponent(btn_send)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(txt_server, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2) + .addComponent(btn_connect) + .addComponent(btn_disconnect)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void txt_serverKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_txt_serverKeyPressed + {//GEN-HEADEREND:event_txt_serverKeyPressed + if (!txt_server.isEnabled()) + { + return; + } + if (evt.getKeyCode() == KeyEvent.VK_ENTER) + { + connection_mgr.trigger_connect(txt_server.getText()); + } + }//GEN-LAST:event_txt_serverKeyPressed + + private void btn_connectMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_connectMouseClicked + {//GEN-HEADEREND:event_btn_connectMouseClicked + if (!btn_connect.isEnabled()) + { + return; + } + connection_mgr.trigger_connect(txt_server.getText()); + }//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 + {//GEN-HEADEREND:event_txt_commandKeyPressed + if (!txt_command.isEnabled()) + { + return; + } + if (evt.getKeyCode() == KeyEvent.VK_ENTER) + { + connection_mgr.send_command(txt_command.getText()); + txt_command.selectAll(); + } + }//GEN-LAST:event_txt_commandKeyPressed + + private void btn_sendMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_sendMouseClicked + {//GEN-HEADEREND:event_btn_sendMouseClicked + if (!btn_send.isEnabled()) + { + return; + } + connection_mgr.send_command(txt_command.getText()); + txt_command.selectAll(); + }//GEN-LAST:event_btn_sendMouseClicked + + public static void main(String args[]) + { + try + { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) + { + if ("Nimbus".equals(info.getName())) + { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } + catch (ClassNotFoundException ex) + { + java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (InstantiationException ex) + { + java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (IllegalAccessException ex) + { + java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (javax.swing.UnsupportedLookAndFeelException ex) + { + java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + + java.awt.EventQueue.invokeLater(new Runnable() + { + public void run() + { + new BukkitTelnetClient().setVisible(true); + } + }); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btn_connect; + private javax.swing.JButton btn_disconnect; + private javax.swing.JButton btn_send; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextPane main_output; + private javax.swing.JTextField txt_command; + private javax.swing.JTextField txt_server; + // End of variables declaration//GEN-END:variables + + public javax.swing.JButton getBtn_connect() + { + return btn_connect; + } + + public javax.swing.JButton getBtn_disconnect() + { + return btn_disconnect; + } + + public javax.swing.JButton getBtn_send() + { + return btn_send; + } + + public javax.swing.JTextPane getMain_output() + { + return main_output; + } + + public javax.swing.JTextField getTxt_command() + { + return txt_command; + } + + public javax.swing.JTextField getTxt_server() + { + return txt_server; + } +} From b6322d9dc4b29d2f1393d02cd6b1bb0b0b0bd6d6 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Sun, 2 Dec 2012 21:07:16 -0500 Subject: [PATCH 3/7] Changed server entry field to combo box that remembers previous server entries. --- nbproject/build-impl.xml | 453 ++++++++++++++++-- nbproject/genfiles.properties | 4 +- nbproject/project.properties | 11 + .../BukkitTelnetClient.form | 29 +- .../BukkitTelnetClient.java | 177 ++++--- 5 files changed, 539 insertions(+), 135 deletions(-) diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 408044f..a9d5c3c 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -12,9 +12,9 @@ is divided into following sections: - execution - debugging - javadoc - - junit compilation - - junit execution - - junit debugging + - test compilation + - test execution + - test debugging - applet - cleanup @@ -156,6 +156,7 @@ is divided into following sections: + @@ -200,6 +201,27 @@ is divided into following sections: + + + + + + + + + + + + + + + + + + + + + @@ -332,11 +354,52 @@ is divided into following sections: - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -345,32 +408,270 @@ is divided into following sections: - - - - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -402,10 +703,13 @@ is divided into following sections: - + Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + @@ -463,6 +767,7 @@ is divided into following sections: + @@ -479,6 +784,7 @@ is divided into following sections: + @@ -486,6 +792,7 @@ is divided into following sections: + @@ -512,6 +819,9 @@ is divided into following sections: + + + @@ -557,7 +867,7 @@ is divided into following sections: - + - + + + This target only works when run from inside the NetBeans IDE. @@ -781,8 +1095,9 @@ is divided into following sections: - + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. @@ -790,12 +1105,8 @@ is divided into following sections: - - + + This target only works when run from inside the NetBeans IDE. @@ -807,12 +1118,8 @@ is divided into following sections: - - + + This target only works when run from inside the NetBeans IDE. @@ -834,6 +1141,42 @@ is divided into following sections: + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + @@ -920,14 +1263,14 @@ is divided into following sections: - + Some tests failed; see details above. @@ -940,39 +1283,40 @@ is divided into following sections: Must select some files in the IDE or set test.includes - + Some tests failed; see details above. + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + - + Must select one file in the IDE or set test.class - - - - - - - - - - - - - - - + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + @@ -1037,9 +1381,12 @@ is divided into following sections: - - - + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 267d65b..66f5a09 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.50.2.46 # 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. nbproject/build-impl.xml.data.CRC32=b147f9b6 -nbproject/build-impl.xml.script.CRC32=8a821c88 -nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.2.46 +nbproject/build-impl.xml.script.CRC32=6eb617a8 +nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 diff --git a/nbproject/project.properties b/nbproject/project.properties index 378deae..8174d05 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -28,7 +28,9 @@ dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= includes=** +jar.archive.disabled=${jnlp.enabled} jar.compress=false +jar.index=${jnlp.enabled} javac.classpath=\ ${libs.Apache_Commons_Lang.classpath}:\ ${libs.Apache_Commons_Net.classpath} @@ -55,6 +57,15 @@ javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= +jnlp.codebase.type=no.codebase +jnlp.descriptor=application +jnlp.enabled=false +jnlp.mixed.code=default +jnlp.offline-allowed=false +jnlp.signed=false +jnlp.signing= +jnlp.signing.alias= +jnlp.signing.keystore= main.class=me.StevenLawson.BukkitTelnetClient.BukkitTelnetClient manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF diff --git a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form index c7b9753..2da4e2a 100644 --- a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form +++ b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form @@ -32,15 +32,10 @@ + - - - - - - - - + + @@ -70,10 +65,10 @@ - + @@ -124,14 +119,6 @@ - - - - - - - - @@ -150,5 +137,13 @@ + + + + + + + + diff --git a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java index e1bd115..ea611cf 100644 --- a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java +++ b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java @@ -1,30 +1,45 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package me.StevenLawson.BukkitTelnetClient; +import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.util.LinkedList; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.SwingUtilities; import javax.swing.text.BadLocationException; import javax.swing.text.Document; -/** - - @author - Steven - */ public class BukkitTelnetClient extends javax.swing.JFrame { + public static final String SERVERS_FILE_NAME = "btc_servers.cfg"; + private static final Logger logger = Logger.getLogger("BukkitTelnetClient"); private BTC_ConnectionManager connection_mgr; + private final LinkedList server_list = new LinkedList(); public BukkitTelnetClient() { initComponents(); + txt_server.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() + { + @Override + public void keyTyped(KeyEvent e) + { + if (e.getKeyChar() == KeyEvent.VK_ENTER) + { + saveServersAndTriggerConnect(); + } + } + }); redirectSystemStreams(); + loadServerList(); connection_mgr = new BTC_ConnectionManager(this); } @@ -76,9 +91,69 @@ public class BukkitTelnetClient extends javax.swing.JFrame System.setErr(new PrintStream(out, true)); } + private void loadServerList() + { + try + { + server_list.clear(); + txt_server.removeAllItems(); + + File file = new File(SERVERS_FILE_NAME); + if (file.exists()) + { + BufferedReader in = new BufferedReader(new FileReader(file)); + String line; + while ((line = in.readLine()) != null) + { + line = line.trim(); + server_list.add(line); + txt_server.addItem(line); + } + in.close(); + } + } + catch (Exception ex) + { + logger.log(Level.SEVERE, null, ex); + } + } + + private void saveServersAndTriggerConnect() + { + String selected_server = (String) txt_server.getSelectedItem(); + + try + { + if (server_list.contains(selected_server)) + { + server_list.remove(selected_server); + } + + server_list.addFirst(selected_server); + + BufferedWriter out = new BufferedWriter(new FileWriter(new File(SERVERS_FILE_NAME))); + + for (String server : server_list) + { + out.write(server + '\n'); + } + + out.close(); + } + catch (Exception ex) + { + logger.log(Level.SEVERE, null, ex); + } + + loadServerList(); + + connection_mgr.trigger_connect(selected_server); + } + @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents - private void initComponents() { + private void initComponents() + { jScrollPane1 = new javax.swing.JScrollPane(); main_output = new javax.swing.JTextPane(); @@ -86,9 +161,9 @@ public class BukkitTelnetClient extends javax.swing.JFrame btn_connect = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); - txt_server = new javax.swing.JTextField(); btn_disconnect = new javax.swing.JButton(); btn_send = new javax.swing.JButton(); + txt_server = new javax.swing.JComboBox(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("BukkitTelnetClient"); @@ -98,15 +173,19 @@ public class BukkitTelnetClient extends javax.swing.JFrame jScrollPane1.setViewportView(main_output); txt_command.setEnabled(false); - txt_command.addKeyListener(new java.awt.event.KeyAdapter() { - public void keyPressed(java.awt.event.KeyEvent evt) { + txt_command.addKeyListener(new java.awt.event.KeyAdapter() + { + public void keyPressed(java.awt.event.KeyEvent evt) + { txt_commandKeyPressed(evt); } }); btn_connect.setText("Connect"); - btn_connect.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { + btn_connect.addMouseListener(new java.awt.event.MouseAdapter() + { + public void mouseClicked(java.awt.event.MouseEvent evt) + { btn_connectMouseClicked(evt); } }); @@ -115,29 +194,28 @@ public class BukkitTelnetClient extends javax.swing.JFrame jLabel2.setText("Server:"); - txt_server.setText("tf.madgeekonline.com:28995"); - txt_server.addKeyListener(new java.awt.event.KeyAdapter() { - public void keyPressed(java.awt.event.KeyEvent evt) { - txt_serverKeyPressed(evt); - } - }); - btn_disconnect.setText("Disconnect"); btn_disconnect.setEnabled(false); - btn_disconnect.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { + btn_disconnect.addMouseListener(new java.awt.event.MouseAdapter() + { + public void mouseClicked(java.awt.event.MouseEvent evt) + { btn_disconnectMouseClicked(evt); } }); btn_send.setText("Send"); btn_send.setEnabled(false); - btn_send.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(java.awt.event.MouseEvent evt) { + btn_send.addMouseListener(new java.awt.event.MouseAdapter() + { + public void mouseClicked(java.awt.event.MouseEvent evt) + { btn_sendMouseClicked(evt); } }); + txt_server.setEditable(true); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -150,13 +228,10 @@ public class BukkitTelnetClient extends javax.swing.JFrame .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel2, 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) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(18, 18, 18) - .addComponent(txt_command)) - .addGroup(layout.createSequentialGroup() - .addGap(17, 17, 17) - .addComponent(txt_server, javax.swing.GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE))) + .addComponent(txt_command, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE) + .addComponent(txt_server, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() @@ -181,35 +256,23 @@ public class BukkitTelnetClient extends javax.swing.JFrame .addComponent(btn_send)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(txt_server, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) .addComponent(btn_connect) - .addComponent(btn_disconnect)) + .addComponent(btn_disconnect) + .addComponent(txt_server, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); pack(); }// //GEN-END:initComponents - private void txt_serverKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_txt_serverKeyPressed - {//GEN-HEADEREND:event_txt_serverKeyPressed - if (!txt_server.isEnabled()) - { - return; - } - if (evt.getKeyCode() == KeyEvent.VK_ENTER) - { - connection_mgr.trigger_connect(txt_server.getText()); - } - }//GEN-LAST:event_txt_serverKeyPressed - private void btn_connectMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_connectMouseClicked {//GEN-HEADEREND:event_btn_connectMouseClicked if (!btn_connect.isEnabled()) { return; } - connection_mgr.trigger_connect(txt_server.getText()); + saveServersAndTriggerConnect(); }//GEN-LAST:event_btn_connectMouseClicked private void btn_disconnectMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_disconnectMouseClicked @@ -257,21 +320,9 @@ public class BukkitTelnetClient extends javax.swing.JFrame } } } - catch (ClassNotFoundException ex) + catch (Exception ex) { - java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - catch (InstantiationException ex) - { - java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - catch (IllegalAccessException ex) - { - java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - catch (javax.swing.UnsupportedLookAndFeelException ex) - { - java.util.logging.Logger.getLogger(BukkitTelnetClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } java.awt.EventQueue.invokeLater(new Runnable() @@ -291,7 +342,7 @@ public class BukkitTelnetClient extends javax.swing.JFrame private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextPane main_output; private javax.swing.JTextField txt_command; - private javax.swing.JTextField txt_server; + private javax.swing.JComboBox txt_server; // End of variables declaration//GEN-END:variables public javax.swing.JButton getBtn_connect() @@ -319,7 +370,7 @@ public class BukkitTelnetClient extends javax.swing.JFrame return txt_command; } - public javax.swing.JTextField getTxt_server() + public javax.swing.JComboBox getTxt_server() { return txt_server; } From 05700c6bba4cee11db9f133801059a7e9a1bab90 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Sun, 2 Dec 2012 21:14:22 -0500 Subject: [PATCH 4/7] Add check to prevent nasty error if no address is entered. --- .../StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java index ea611cf..a6f6502 100644 --- a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java +++ b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java @@ -122,6 +122,12 @@ public class BukkitTelnetClient extends javax.swing.JFrame { String selected_server = (String) txt_server.getSelectedItem(); + if (selected_server == null || selected_server.isEmpty()) + { + System.out.println("Invalid server address."); + return; + } + try { if (server_list.contains(selected_server)) From 3772207820be9983efb4c19f3a0f36336547259e Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Sat, 15 Dec 2012 16:01:38 -0500 Subject: [PATCH 5/7] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc96d37..4953b64 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ BukkitTelnetClient ================== -BukkitTelnetClient is a very, very basic telnet client for use with the BukkitTelnet CraftBukkit plugin. \ No newline at end of file +BukkitTelnetClient is a very, very basic telnet client for use with the BukkitTelnet CraftBukkit plugin. + +A recent binary can be found here: +https://s3.amazonaws.com/StevenLawson/BukkitTelnetClient.jar From 7236d9d867375b0fc1f7d05a60238e6ae1813386 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Sat, 15 Dec 2012 22:42:29 -0500 Subject: [PATCH 6/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4953b64..8c2e3b4 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ BukkitTelnetClient BukkitTelnetClient is a very, very basic telnet client for use with the BukkitTelnet CraftBukkit plugin. A recent binary can be found here: -https://s3.amazonaws.com/StevenLawson/BukkitTelnetClient.jar +http://s3.madgeekonline.com/BukkitTelnetClient.jar From 23e1af4e9e36bde0b99f22e6a1b269b2da0c0c69 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Fri, 2 Aug 2013 21:04:47 -0400 Subject: [PATCH 7/7] Added options to enable and disable autoscrolling. Update to Java 1.7. A few other bugfixes. --- README.md | 2 +- nbproject/build-impl.xml | 44 ++-- nbproject/genfiles.properties | 10 +- nbproject/project.properties | 7 +- nbproject/project.xml | 4 +- .../BTC_ConnectionManager.java | 4 + .../BukkitTelnetClient.form | 34 +++- .../BukkitTelnetClient.java | 191 +++++++++++------- 8 files changed, 179 insertions(+), 117 deletions(-) diff --git a/README.md b/README.md index 8c2e3b4..38454ed 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ BukkitTelnetClient BukkitTelnetClient is a very, very basic telnet client for use with the BukkitTelnet CraftBukkit plugin. A recent binary can be found here: -http://s3.madgeekonline.com/BukkitTelnetClient.jar +http://s3.madgeekonline.com/BukkitTelnetClient-v1_3.jar diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index a9d5c3c..e43ea92 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -134,9 +134,7 @@ is divided into following sections: - - - + @@ -229,7 +227,6 @@ is divided into following sections: Must set src.dir - Must set test.src.dir Must set build.dir Must set dist.dir Must set build.classes.dir @@ -370,6 +367,11 @@ is divided into following sections: + + + + + @@ -393,7 +395,7 @@ is divided into following sections: - + @@ -404,8 +406,8 @@ is divided into following sections: - - + + @@ -432,11 +434,7 @@ is divided into following sections: - - - - - + @@ -534,7 +532,7 @@ is divided into following sections: - + @@ -545,8 +543,8 @@ is divided into following sections: - - + + @@ -920,7 +918,7 @@ is divided into following sections: - + @@ -1231,13 +1229,11 @@ is divided into following sections: - + - - - - + + @@ -1251,10 +1247,8 @@ is divided into following sections: Must select some files in the IDE or set javac.includes - - - - + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 66f5a09..25c8ed8 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=b147f9b6 +build.xml.data.CRC32=b53f58a0 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. # 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.script.CRC32=6eb617a8 -nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 +nbproject/build-impl.xml.data.CRC32=b53f58a0 +nbproject/build-impl.xml.script.CRC32=5a1afff7 +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff --git a/nbproject/project.properties b/nbproject/project.properties index 8174d05..a8756e0 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -35,12 +35,12 @@ javac.classpath=\ ${libs.Apache_Commons_Lang.classpath}:\ ${libs.Apache_Commons_Net.classpath} # Space-separated list of extra javac options -javac.compilerargs= +javac.compilerargs=-Xlint:unchecked javac.deprecation=false javac.processorpath=\ ${javac.classpath} -javac.source=1.6 -javac.target=1.6 +javac.source=1.7 +javac.target=1.7 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} @@ -83,4 +83,3 @@ run.test.classpath=\ ${build.test.classes.dir} source.encoding=UTF-8 src.dir=src -test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml index 08ad5eb..aca1fea 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -7,9 +7,7 @@ - - - + diff --git a/src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java b/src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java index 9d8ba57..996c5e5 100644 --- a/src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java +++ b/src/me/StevenLawson/BukkitTelnetClient/BTC_ConnectionManager.java @@ -29,6 +29,8 @@ public class BTC_ConnectionManager btc.getTxt_server().setEnabled(false); btc.getBtn_disconnect().setEnabled(true); + this.btc.setTitle("BukkitTelnetClient - v1.3 - " + hostname + ":" + port); + System.out.println("Connecting to " + hostname + ":" + port + "..."); this.hostname = hostname; @@ -86,6 +88,8 @@ public class BTC_ConnectionManager btc.getBtn_send().setEnabled(false); btc.getTxt_command().setEnabled(false); + this.btc.setTitle("BukkitTelnetClient - v1.3 - Disconnected"); + System.out.println("\nDisconnected."); } diff --git a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form index 2da4e2a..62b3b0c 100644 --- a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form +++ b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.form @@ -7,6 +7,7 @@ + @@ -34,17 +35,18 @@ - + - - - - - - + + + + + + + @@ -56,12 +58,13 @@ - + + @@ -106,7 +109,7 @@ - + @@ -125,7 +128,7 @@ - + @@ -134,7 +137,7 @@ - + @@ -145,5 +148,14 @@ + + + + + + + + + diff --git a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java index a6f6502..4afb27d 100644 --- a/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java +++ b/src/me/StevenLawson/BukkitTelnetClient/BukkitTelnetClient.java @@ -22,25 +22,36 @@ public class BukkitTelnetClient extends javax.swing.JFrame public static final String SERVERS_FILE_NAME = "btc_servers.cfg"; private static final Logger logger = Logger.getLogger("BukkitTelnetClient"); private BTC_ConnectionManager connection_mgr; - private final LinkedList server_list = new LinkedList(); + private final LinkedList server_list = new LinkedList<>(); + private static BukkitTelnetClient btc = null; - public BukkitTelnetClient() + private static void setup() { - initComponents(); - txt_server.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() + btc = new BukkitTelnetClient(); + + btc.initComponents(); + + btc.setLocationRelativeTo(null); + + btc.txt_server.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_ENTER) { - saveServersAndTriggerConnect(); + btc.saveServersAndTriggerConnect(); } } }); - redirectSystemStreams(); - loadServerList(); - connection_mgr = new BTC_ConnectionManager(this); + + btc.redirectSystemStreams(); + + btc.loadServerList(); + + btc.connection_mgr = new BTC_ConnectionManager(btc); + + btc.setVisible(true); } private void updateTextPane(final String text) @@ -59,7 +70,10 @@ public class BukkitTelnetClient extends javax.swing.JFrame { 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)); } + @SuppressWarnings("unchecked") private void loadServerList() { try @@ -101,15 +116,16 @@ public class BukkitTelnetClient extends javax.swing.JFrame File file = new File(SERVERS_FILE_NAME); if (file.exists()) { - BufferedReader in = new BufferedReader(new FileReader(file)); - String line; - while ((line = in.readLine()) != null) + try (BufferedReader in = new BufferedReader(new FileReader(file))) { - line = line.trim(); - server_list.add(line); - txt_server.addItem(line); + String line; + while ((line = in.readLine()) != null) + { + line = line.trim(); + server_list.add(line); + txt_server.addItem(line); + } } - in.close(); } } catch (Exception ex) @@ -136,15 +152,13 @@ public class BukkitTelnetClient extends javax.swing.JFrame } server_list.addFirst(selected_server); - - BufferedWriter out = new BufferedWriter(new FileWriter(new File(SERVERS_FILE_NAME))); - - for (String server : server_list) + try (BufferedWriter out = new BufferedWriter(new FileWriter(new File(SERVERS_FILE_NAME)))) { - out.write(server + '\n'); + for (String server : server_list) + { + out.write(server + '\n'); + } } - - out.close(); } catch (Exception ex) { @@ -170,6 +184,7 @@ public class BukkitTelnetClient extends javax.swing.JFrame btn_disconnect = new javax.swing.JButton(); btn_send = new javax.swing.JButton(); txt_server = new javax.swing.JComboBox(); + chkAutoScroll = new javax.swing.JCheckBox(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("BukkitTelnetClient"); @@ -188,11 +203,11 @@ public class BukkitTelnetClient extends javax.swing.JFrame }); 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.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.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); + 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()); getContentPane().setLayout(layout); 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)) .addGap(18, 18, 18) .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)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(layout.createSequentialGroup() - .addComponent(btn_connect) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btn_disconnect)) - .addComponent(btn_send, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) + .addComponent(btn_connect, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(btn_send, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(btn_disconnect) + .addComponent(chkAutoScroll)))) .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.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .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) .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(jLabel1) - .addComponent(btn_send)) + .addComponent(btn_send) + .addComponent(chkAutoScroll)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) @@ -272,24 +299,6 @@ public class BukkitTelnetClient extends javax.swing.JFrame pack(); }// //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 {//GEN-HEADEREND:event_txt_commandKeyPressed if (!txt_command.isEnabled()) @@ -303,39 +312,84 @@ public class BukkitTelnetClient extends javax.swing.JFrame } }//GEN-LAST:event_txt_commandKeyPressed - private void btn_sendMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_btn_sendMouseClicked - {//GEN-HEADEREND:event_btn_sendMouseClicked + private void chkAutoScrollActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_chkAutoScrollActionPerformed + {//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()) { return; } connection_mgr.send_command(txt_command.getText()); 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 { - 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; } + else if ("Nimbus".equalsIgnoreCase(style.getName())) + { + fallbackStyle = style; + } + } + + if (foundStyle != null) + { + javax.swing.UIManager.setLookAndFeel(foundStyle.getClassName()); + } + else if (fallbackStyle != null) + { + javax.swing.UIManager.setLookAndFeel(fallbackStyle.getClassName()); } } - catch (Exception ex) + catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { logger.log(Level.SEVERE, null, ex); } + } + + public static void main(String args[]) + { + findAndSetLookAndFeel("Windows"); java.awt.EventQueue.invokeLater(new Runnable() { + @Override 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_disconnect; private javax.swing.JButton btn_send; + private javax.swing.JCheckBox chkAutoScroll; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1;