Improved error/warning ignore & coloring feature.

This commit is contained in:
StevenLawson 2014-08-21 22:40:05 -04:00
parent a6be8fb5a0
commit e8c146bca3
3 changed files with 91 additions and 25 deletions

View file

@ -5,7 +5,7 @@ import java.awt.Color;
public class BTC_ConsoleMessage public class BTC_ConsoleMessage
{ {
private final String message; private final String message;
private final Color color; private Color color;
public BTC_ConsoleMessage(final String message) public BTC_ConsoleMessage(final String message)
{ {
@ -28,4 +28,9 @@ public class BTC_ConsoleMessage
{ {
return color; return color;
} }
public void setColor(Color color)
{
this.color = color;
}
} }

View file

@ -53,18 +53,66 @@ public class BTC_MainPanel extends javax.swing.JFrame
this.setVisible(true); this.setVisible(true);
} }
public final void writeToConsole(final BTC_ConsoleMessage message) private final Queue<BTC_TelnetMessage> telnetErrorQueue = new LinkedList<>();
private boolean isQueueing = false;
private void flushTelnetErrorQueue()
{
BTC_TelnetMessage queuedMessage;
while ((queuedMessage = telnetErrorQueue.poll()) != null)
{
queuedMessage.setColor(Color.GRAY);
writeToConsoleImmediately(queuedMessage, true);
}
}
public void writeToConsole(final BTC_ConsoleMessage message)
{ {
if (message.getMessage().isEmpty()) if (message.getMessage().isEmpty())
{ {
return; return;
} }
if (message instanceof BTC_TelnetMessage)
{
final BTC_TelnetMessage telnetMessage = (BTC_TelnetMessage) message;
if (telnetMessage.isInfoMessage())
{
isQueueing = false;
flushTelnetErrorQueue();
}
else if (telnetMessage.isErrorMessage() || isQueueing)
{
isQueueing = true;
telnetErrorQueue.add(telnetMessage);
}
if (!isQueueing)
{
writeToConsoleImmediately(telnetMessage, false);
}
}
else
{
isQueueing = false;
flushTelnetErrorQueue();
writeToConsoleImmediately(message, false);
}
}
private void writeToConsoleImmediately(final BTC_ConsoleMessage message, final boolean isTelnetError)
{
SwingUtilities.invokeLater(new Runnable() SwingUtilities.invokeLater(new Runnable()
{ {
@Override @Override
public void run() public void run()
{ {
if (isTelnetError && chkIgnoreErrors.isSelected())
{
return;
}
final StyledDocument styledDocument = mainOutput.getStyledDocument(); final StyledDocument styledDocument = mainOutput.getStyledDocument();
int startLength = styledDocument.getLength(); int startLength = styledDocument.getLength();

View file

@ -9,6 +9,9 @@ public class BTC_TelnetMessage extends BTC_ConsoleMessage
private static final Color PURPLE = new Color(128, 0, 128); private static final Color PURPLE = new Color(128, 0, 128);
private static final Color DARK_GREEN = new Color(86, 130, 3); private static final Color DARK_GREEN = new Color(86, 130, 3);
private static final Pattern ERROR_MESSAGE = Pattern.compile("^:\\[.+? (?:(WARN)|(ERROR))\\]: ");
private static final Pattern INFO_MESSAGE = Pattern.compile(PATTERN_PREFIX);
private final BTC_LogMessageType messageType; private final BTC_LogMessageType messageType;
public BTC_TelnetMessage(String message) public BTC_TelnetMessage(String message)
@ -22,6 +25,21 @@ public class BTC_TelnetMessage extends BTC_ConsoleMessage
return this.messageType; return this.messageType;
} }
public boolean isErrorMessage()
{
return ERROR_MESSAGE.matcher(this.getMessage()).find();
}
public boolean isInfoMessage()
{
return INFO_MESSAGE.matcher(this.getMessage()).find();
}
private boolean isType(final BTC_LogMessageType checkType)
{
return this.messageType == checkType;
}
public boolean skip() public boolean skip()
{ {
final BTC_MainPanel mainPanel = BukkitTelnetClient.mainPanel; final BTC_MainPanel mainPanel = BukkitTelnetClient.mainPanel;
@ -30,37 +48,36 @@ public class BTC_TelnetMessage extends BTC_ConsoleMessage
{ {
return false; return false;
} }
if (mainPanel.getChkShowChatOnly().isSelected()) if (mainPanel.getChkShowChatOnly().isSelected())
{ {
switch (messageType) if (!isType(BTC_LogMessageType.CHAT_MESSAGE)
&& !isType(BTC_LogMessageType.CSAY_MESSAGE)
&& !isType(BTC_LogMessageType.SAY_MESSAGE)
&& !isType(BTC_LogMessageType.ADMINSAY_MESSAGE))
{ {
case CHAT_MESSAGE:
case CSAY_MESSAGE:
case SAY_MESSAGE:
case ADMINSAY_MESSAGE:
return false; return false;
default:
return true;
} }
} }
else if (mainPanel.getChkIgnoreServerCommands().isSelected() && this.messageType == BTC_LogMessageType.ISSUED_SERVER_COMMAND)
if (mainPanel.getChkIgnoreServerCommands().isSelected() && this.messageType == BTC_LogMessageType.ISSUED_SERVER_COMMAND)
{ {
return true; return true;
} }
else if (mainPanel.getChkIgnorePlayerCommands().isSelected() && this.messageType == BTC_LogMessageType.PLAYER_COMMAND)
if (mainPanel.getChkIgnorePlayerCommands().isSelected() && this.messageType == BTC_LogMessageType.PLAYER_COMMAND)
{ {
return true; return true;
} }
else if (mainPanel.getChkIgnoreErrors().isSelected())
if (mainPanel.getChkIgnoreErrors().isSelected())
{ {
switch (this.messageType) if (!isType(BTC_LogMessageType.CHAT_MESSAGE)
&& !isType(BTC_LogMessageType.CSAY_MESSAGE)
&& !isType(BTC_LogMessageType.SAY_MESSAGE)
&& !isType(BTC_LogMessageType.ADMINSAY_MESSAGE))
{ {
case ERROR_MESSAGE:
case STACK_TRACE:
case EXCEPTION_MESSAGE:
return false; return false;
default:
return true;
} }
} }
@ -93,11 +110,7 @@ public class BTC_TelnetMessage extends BTC_ConsoleMessage
PREPROCESS_COMMAND(PATTERN_PREFIX + "\\[PREPROCESS_COMMAND\\] ", DARK_GREEN), PREPROCESS_COMMAND(PATTERN_PREFIX + "\\[PREPROCESS_COMMAND\\] ", DARK_GREEN),
// //
ISSUED_SERVER_COMMAND(PATTERN_PREFIX + ".+? issued server command: "), ISSUED_SERVER_COMMAND(PATTERN_PREFIX + ".+? issued server command: "),
PLAYER_COMMAND(PATTERN_PREFIX + "\\[PLAYER_COMMAND\\] "), PLAYER_COMMAND(PATTERN_PREFIX + "\\[PLAYER_COMMAND\\] ");
//
ERROR_MESSAGE("^:\\[.+? (!?(WARN)|(ERROR))\\]: ", Color.LIGHT_GRAY),
EXCEPTION_MESSAGE("^[^\\[][^\\s]+: ", Color.LIGHT_GRAY),
STACK_TRACE("^\\t", Color.LIGHT_GRAY);
private final Pattern messagePattern; private final Pattern messagePattern;
private final Color color; private final Color color;