mirror of
https://github.com/TotalFreedomMC/ZeroTelnetClient.git
synced 2024-12-23 00:35:22 +00:00
Made autoscroll work better.
Fixed a few glitches in console output.
This commit is contained in:
parent
4b632bdd23
commit
7569cbfaf2
4 changed files with 59 additions and 29 deletions
5
pom.xml
5
pom.xml
|
@ -43,11 +43,6 @@
|
||||||
<artifactId>commons-net</artifactId>
|
<artifactId>commons-net</artifactId>
|
||||||
<version>3.3</version>
|
<version>3.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>2.4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.json</groupId>
|
<groupId>org.json</groupId>
|
||||||
<artifactId>json</artifactId>
|
<artifactId>json</artifactId>
|
||||||
|
|
|
@ -20,6 +20,7 @@ public class BTC_ConnectionManager
|
||||||
private int port;
|
private int port;
|
||||||
private boolean canDoDisconnect = false;
|
private boolean canDoDisconnect = false;
|
||||||
private String loginName;
|
private String loginName;
|
||||||
|
final ByteArrayOutputStream consoleBuffer = new ByteArrayOutputStream();
|
||||||
|
|
||||||
public BTC_ConnectionManager()
|
public BTC_ConnectionManager()
|
||||||
{
|
{
|
||||||
|
@ -113,7 +114,12 @@ public class BTC_ConnectionManager
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
BTC_MainPanel.CONSOLE_STREAM.format("%s\r\n", text);
|
final BTC_MainPanel btc = BukkitTelnetClient.mainPanel;
|
||||||
|
|
||||||
|
String buffer = consoleBuffer.toString();
|
||||||
|
consoleBuffer.reset();
|
||||||
|
|
||||||
|
btc.writeToConsole(buffer + text);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.telnetClient.getOutputStream().write((text + "\n").getBytes());
|
this.telnetClient.getOutputStream().write((text + "\n").getBytes());
|
||||||
|
@ -153,7 +159,6 @@ public class BTC_ConnectionManager
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
final BTC_MainPanel btc = BukkitTelnetClient.mainPanel;
|
final BTC_MainPanel btc = BukkitTelnetClient.mainPanel;
|
||||||
final ByteArrayOutputStream consoleBuffer = new ByteArrayOutputStream();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -232,7 +237,8 @@ public class BTC_ConnectionManager
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
|
ex.printStackTrace(BTC_MainPanel.CONSOLE_STREAM);
|
||||||
|
btc.updateConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
finishDisconnect();
|
finishDisconnect();
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
<SubComponents>
|
<SubComponents>
|
||||||
<Container class="javax.swing.JSplitPane" name="splitPane">
|
<Container class="javax.swing.JSplitPane" name="splitPane">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="dividerLocation" type="int" value="700"/>
|
<Property name="resizeWeight" type="double" value="1.0"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
|
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
<Group type="102" alignment="0" attributes="0">
|
<Group type="102" alignment="0" attributes="0">
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<Component id="jScrollPane1" max="32767" attributes="0"/>
|
<Component id="mainOutputScoll" max="32767" attributes="0"/>
|
||||||
<Group type="102" attributes="0">
|
<Group type="102" attributes="0">
|
||||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||||
<Component id="jLabel2" max="32767" attributes="0"/>
|
<Component id="jLabel2" max="32767" attributes="0"/>
|
||||||
|
@ -93,7 +93,7 @@
|
||||||
<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 min="-2" max="-2" attributes="0"/>
|
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||||
<Component id="jScrollPane1" pref="360" max="32767" attributes="0"/>
|
<Component id="mainOutputScoll" pref="360" max="32767" attributes="0"/>
|
||||||
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
|
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
|
||||||
<Group type="103" groupAlignment="3" attributes="0">
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
<Component id="txtCommand" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="txtCommand" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
@ -114,7 +114,7 @@
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
</Layout>
|
</Layout>
|
||||||
<SubComponents>
|
<SubComponents>
|
||||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
<Container class="javax.swing.JScrollPane" name="mainOutputScoll">
|
||||||
<AuxValues>
|
<AuxValues>
|
||||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||||
</AuxValues>
|
</AuxValues>
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="editable" type="boolean" value="false"/>
|
<Property name="editable" type="boolean" value="false"/>
|
||||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||||
<Font name="Courier New" size="12" style="0"/>
|
<Font name="Courier New" size="11" style="0"/>
|
||||||
</Property>
|
</Property>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Component>
|
</Component>
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -25,8 +26,10 @@ import java.util.logging.Level;
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.JScrollBar;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.Timer;
|
||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
import javax.swing.text.BadLocationException;
|
import javax.swing.text.BadLocationException;
|
||||||
import javax.swing.text.SimpleAttributeSet;
|
import javax.swing.text.SimpleAttributeSet;
|
||||||
|
@ -71,8 +74,6 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
setIconImage(Toolkit.getDefaultToolkit().createImage(icon));
|
setIconImage(Toolkit.getDefaultToolkit().createImage(icon));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.splitPane.setResizeWeight(1.0);
|
|
||||||
|
|
||||||
setupTablePopup();
|
setupTablePopup();
|
||||||
|
|
||||||
this.connectionManager.updateTitle(false);
|
this.connectionManager.updateTitle(false);
|
||||||
|
@ -81,8 +82,13 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void updateTextPane(final String text)
|
public final void updateTextPane(final String line)
|
||||||
{
|
{
|
||||||
|
if (line.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SwingUtilities.invokeLater(new Runnable()
|
SwingUtilities.invokeLater(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,12 +96,14 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
{
|
{
|
||||||
final StyledDocument styledDocument = mainOutput.getStyledDocument();
|
final StyledDocument styledDocument = mainOutput.getStyledDocument();
|
||||||
|
|
||||||
|
int startLength = styledDocument.getLength();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
styledDocument.insertString(
|
styledDocument.insertString(
|
||||||
styledDocument.getLength(),
|
styledDocument.getLength(),
|
||||||
text,
|
line,
|
||||||
StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, BTC_FormatHandler.getColor(text))
|
StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, BTC_FormatHandler.getColor(line))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (BadLocationException ex)
|
catch (BadLocationException ex)
|
||||||
|
@ -105,7 +113,26 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
|
|
||||||
if (BTC_MainPanel.this.chkAutoScroll.isSelected() && BTC_MainPanel.this.mainOutput.getSelectedText() == null)
|
if (BTC_MainPanel.this.chkAutoScroll.isSelected() && BTC_MainPanel.this.mainOutput.getSelectedText() == null)
|
||||||
{
|
{
|
||||||
BTC_MainPanel.this.mainOutput.setCaretPosition(styledDocument.getLength() - 1);
|
final JScrollBar vScroll = mainOutputScoll.getVerticalScrollBar();
|
||||||
|
|
||||||
|
if (!vScroll.getValueIsAdjusting())
|
||||||
|
{
|
||||||
|
if (vScroll.getValue() + vScroll.getModel().getExtent() >= (vScroll.getMaximum() - 10))
|
||||||
|
{
|
||||||
|
BTC_MainPanel.this.mainOutput.setCaretPosition(startLength);
|
||||||
|
|
||||||
|
final Timer timer = new Timer(10, new ActionListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent ae)
|
||||||
|
{
|
||||||
|
vScroll.setValue(vScroll.getMaximum());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timer.setRepeats(false);
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -119,7 +146,10 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
final String[] lines = data.split("\\n");
|
final String[] lines = data.split("\\n");
|
||||||
for (String line : lines)
|
for (String line : lines)
|
||||||
{
|
{
|
||||||
updateTextPane(line + '\n');
|
if (!line.isEmpty())
|
||||||
|
{
|
||||||
|
updateTextPane(line + '\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,7 +488,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
|
|
||||||
splitPane = new javax.swing.JSplitPane();
|
splitPane = new javax.swing.JSplitPane();
|
||||||
jPanel3 = new javax.swing.JPanel();
|
jPanel3 = new javax.swing.JPanel();
|
||||||
jScrollPane1 = new javax.swing.JScrollPane();
|
mainOutputScoll = new javax.swing.JScrollPane();
|
||||||
mainOutput = new javax.swing.JTextPane();
|
mainOutput = new javax.swing.JTextPane();
|
||||||
btnDisconnect = new javax.swing.JButton();
|
btnDisconnect = new javax.swing.JButton();
|
||||||
btnSend = new javax.swing.JButton();
|
btnSend = new javax.swing.JButton();
|
||||||
|
@ -480,11 +510,11 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
setTitle("BukkitTelnetClient");
|
setTitle("BukkitTelnetClient");
|
||||||
|
|
||||||
splitPane.setDividerLocation(700);
|
splitPane.setResizeWeight(1.0);
|
||||||
|
|
||||||
mainOutput.setEditable(false);
|
mainOutput.setEditable(false);
|
||||||
mainOutput.setFont(new java.awt.Font("Courier New", 0, 12)); // NOI18N
|
mainOutput.setFont(new java.awt.Font("Courier New", 0, 11)); // NOI18N
|
||||||
jScrollPane1.setViewportView(mainOutput);
|
mainOutputScoll.setViewportView(mainOutput);
|
||||||
|
|
||||||
btnDisconnect.setText("Disconnect");
|
btnDisconnect.setText("Disconnect");
|
||||||
btnDisconnect.setEnabled(false);
|
btnDisconnect.setEnabled(false);
|
||||||
|
@ -547,7 +577,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
.addGroup(jPanel3Layout.createSequentialGroup()
|
.addGroup(jPanel3Layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addComponent(jScrollPane1)
|
.addComponent(mainOutputScoll)
|
||||||
.addGroup(jPanel3Layout.createSequentialGroup()
|
.addGroup(jPanel3Layout.createSequentialGroup()
|
||||||
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||||
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||||
|
@ -573,7 +603,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(jPanel3Layout.createSequentialGroup()
|
.addGroup(jPanel3Layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
|
.addComponent(mainOutputScoll, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||||
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(txtCommand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(txtCommand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
@ -622,7 +652,6 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
return canEdit [columnIndex];
|
return canEdit [columnIndex];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tblPlayers.setRowSelectionAllowed(true);
|
|
||||||
tblPlayers.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
tblPlayers.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
||||||
jScrollPane2.setViewportView(tblPlayers);
|
jScrollPane2.setViewportView(tblPlayers);
|
||||||
tblPlayers.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
tblPlayers.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
@ -724,7 +753,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
|
|
||||||
private void chkAutoScrollActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_chkAutoScrollActionPerformed
|
private void chkAutoScrollActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_chkAutoScrollActionPerformed
|
||||||
{//GEN-HEADEREND:event_chkAutoScrollActionPerformed
|
{//GEN-HEADEREND:event_chkAutoScrollActionPerformed
|
||||||
updateTextPane("");
|
// updateTextPane("");
|
||||||
}//GEN-LAST:event_chkAutoScrollActionPerformed
|
}//GEN-LAST:event_chkAutoScrollActionPerformed
|
||||||
|
|
||||||
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnConnectActionPerformed
|
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnConnectActionPerformed
|
||||||
|
@ -775,10 +804,10 @@ public class BTC_MainPanel extends javax.swing.JFrame
|
||||||
private javax.swing.JPanel jPanel1;
|
private javax.swing.JPanel jPanel1;
|
||||||
private javax.swing.JPanel jPanel2;
|
private javax.swing.JPanel jPanel2;
|
||||||
private javax.swing.JPanel jPanel3;
|
private javax.swing.JPanel jPanel3;
|
||||||
private javax.swing.JScrollPane jScrollPane1;
|
|
||||||
private javax.swing.JScrollPane jScrollPane2;
|
private javax.swing.JScrollPane jScrollPane2;
|
||||||
private javax.swing.JTabbedPane jTabbedPane1;
|
private javax.swing.JTabbedPane jTabbedPane1;
|
||||||
private javax.swing.JTextPane mainOutput;
|
private javax.swing.JTextPane mainOutput;
|
||||||
|
private javax.swing.JScrollPane mainOutputScoll;
|
||||||
private javax.swing.JSplitPane splitPane;
|
private javax.swing.JSplitPane splitPane;
|
||||||
private javax.swing.JTable tblPlayers;
|
private javax.swing.JTable tblPlayers;
|
||||||
private javax.swing.JTextField txtCommand;
|
private javax.swing.JTextField txtCommand;
|
||||||
|
|
Loading…
Reference in a new issue