Permalink
Browse files

Maven pom target set to 1.6; Debug tab added; Safety checks added to …

…saved chat window position loading; Caught exception when loading bad format custom PNG
  • Loading branch information...
GlitchCog committed May 26, 2016
1 parent f79b2c0 commit 7747cc19a405f241f7cc159684c0c5baa4707f19
BIN +14 KB (100%) jar/ChatGameFontificator.jar
Binary file not shown.
11 pom.xml
@@ -62,6 +62,17 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
@@ -23,6 +23,8 @@
{
private static final Logger logger = Logger.getLogger(FontificatorMain.class);
public final static PatternLayout LOG_PATTERN_LAYOUT = new PatternLayout("[%p] %d{MM-dd-yyyy HH:mm:ss} %c %M - %m%n");
/**
* The main method for the program
*
@@ -33,7 +35,7 @@
public static void main(String[] args)
{
// Configure the logger
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("[%p] %d{MM-dd-yyyy HH:mm:ss} %c %M - %m%n")));
BasicConfigurator.configure(new ConsoleAppender(LOG_PATTERN_LAYOUT));
Logger.getRootLogger().setLevel(Level.INFO);
try
@@ -0,0 +1,61 @@
package com.glitchcog.fontificator.gui;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.Thread.UncaughtExceptionHandler;
import org.apache.log4j.Level;
import org.apache.log4j.WriterAppender;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;
import com.glitchcog.fontificator.FontificatorMain;
import com.glitchcog.fontificator.gui.controls.panel.LogBox;
public class DebugAppender extends WriterAppender implements UncaughtExceptionHandler
{
private LogBox debugLogBox;
public DebugAppender(LogBox debugLogBox)
{
super(FontificatorMain.LOG_PATTERN_LAYOUT, System.out);
this.debugLogBox = debugLogBox;
setName("Debug Logging");
setThreshold(Level.DEBUG);
}
@Override
public void append(LoggingEvent event)
{
debugLogBox.log(this.layout.format(event));
ThrowableInformation info = event.getThrowableInformation();
if (info != null && info.getThrowable() != null)
{
Throwable t = info.getThrowable();
debugLogBox.log(throwableToString(t));
}
}
@Override
public void uncaughtException(Thread t, Throwable e)
{
try
{
System.err.println("Exception in thread \"" + t.getName() + "\" ");
e.printStackTrace(System.err);
debugLogBox.log("Exception in thread \"" + t.getName() + "\" ");
debugLogBox.log(throwableToString(e));
}
catch (Exception debugException)
{
debugException.printStackTrace();
}
}
private static String throwableToString(Throwable e)
{
StringWriter stackTraceWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stackTraceWriter));
return stackTraceWriter.toString();
}
}
@@ -347,8 +347,9 @@ private void initMenus()
/* Help Menu Item Text */
final String strHelpHelp = "Help";
final String strHelpDebug = "Debug Mode";
final String strHelpAbout = "About";
final MenuComponent[] helpComponents = new MenuComponent[] { new MenuComponent(strHelpHelp, KeyEvent.VK_R, null), null, new MenuComponent(strHelpAbout, KeyEvent.VK_A, null) };
final MenuComponent[] helpComponents = new MenuComponent[] { new MenuComponent(strHelpHelp, KeyEvent.VK_R, null), new MenuComponent(strHelpDebug, KeyEvent.VK_D, null, true), null, new MenuComponent(strHelpAbout, KeyEvent.VK_A, null) };
/* All menu components, with a placeholder for the Presets menu */
final MenuComponent[][] allMenuComponents = new MenuComponent[][] { fileComponents, new MenuComponent[] {}, viewComponents, messageComponents, helpComponents };
@@ -416,6 +417,10 @@ else if (strHelpHelp.equals(mi.getText()))
{
help.setVisible(true);
}
else if (strHelpDebug.equals(mi.getText()))
{
toggleDebugTab();
}
else if (strHelpAbout.equals(mi.getText()))
{
showAboutPane();
@@ -928,6 +933,11 @@ public void hyperlinkUpdate(HyperlinkEvent e)
aboutPane.setEditable(false);
}
private void toggleDebugTab()
{
controlTabs.toggleDebugTab();
}
private void showAboutPane()
{
JOptionPane.showMessageDialog(this, aboutPane, "About", JOptionPane.PLAIN_MESSAGE);
@@ -1,6 +1,8 @@
package com.glitchcog.fontificator.gui.controls.panel;
import java.awt.Component;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
@@ -511,16 +513,8 @@ public void fillInputAfterLoading()
{
ctrlWindow.setAlwaysOnTopMenu(config.isAlwaysOnTop());
ctrlWindow.setRememberPositionMenu(config.isRememberPosition());
if (config.isRememberPosition())
{
final int cwpx = config.getChatWindowPositionX();
final int cwpy = config.getChatWindowPositionY();
// TODO validate screen positions
chatWindow.setLocation(cwpx, cwpy);
}
ctrlWindow.setAntiAliasMenu(config.isAntiAlias());
setRememberedPosition();
}
@Override
@@ -565,7 +559,46 @@ public void setRememberedPosition()
{
if (config != null && config.isRememberPosition())
{
chatWindow.setLocation(config.getChatWindowPositionX(), config.getChatWindowPositionY());
int cwpx = config.getChatWindowPositionX();
int cwpy = config.getChatWindowPositionY();
GraphicsDevice[] devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
int totalWidth = 0;
int totalHeight = 0;
for (GraphicsDevice dev : devs)
{
if (dev.getDisplayMode() != null)
{
totalWidth += dev.getDisplayMode().getWidth();
totalHeight += dev.getDisplayMode().getHeight();
}
}
// Put it back on the screen
totalWidth -= chatWindow.getWidth();
totalHeight -= chatWindow.getHeight();
// Right / bottom boundary check
if (cwpx > totalWidth)
{
cwpx = totalWidth;
}
if (cwpy > totalHeight)
{
cwpy = totalHeight;
}
// Left / top boundary check
if (cwpx < 0)
{
cwpx = 0;
}
if (cwpy < 0)
{
cwpy = 0;
}
chatWindow.setLocation(cwpx, cwpy);
}
}
@@ -0,0 +1,91 @@
package com.glitchcog.fontificator.gui.controls.panel;
import java.awt.GridBagConstraints;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import com.glitchcog.fontificator.config.FontificatorProperties;
import com.glitchcog.fontificator.config.loadreport.LoadConfigReport;
import com.glitchcog.fontificator.gui.DebugAppender;
import com.glitchcog.fontificator.gui.chat.ChatWindow;
/**
* Control Panel containing debugging options and information
*
* @author Matt Yanos
*/
public class ControlPanelDebug extends ControlPanelBase
{
private static final long serialVersionUID = 1L;
private DebugAppender debugAppender;
/**
* Construct an IRC (Connection) control panel
*
* @param fProps
* @param chatWindow
* @param bot
* @param logBox
*/
public ControlPanelDebug(FontificatorProperties fProps, ChatWindow chatWindow)
{
super("Debug", fProps, chatWindow, new LogBox());
debugAppender = new DebugAppender(logBox);
}
@Override
protected void build()
{
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.anchor = GridBagConstraints.SOUTH;
gbc.fill = GridBagConstraints.BOTH;
add(logBox, gbc);
}
@Override
protected void fillInputFromProperties(FontificatorProperties fProps)
{
fillInputFromConfig();
}
@Override
protected void fillInputFromConfig()
{
}
@Override
protected LoadConfigReport validateInput()
{
return new LoadConfigReport();
}
@Override
public void fillConfigFromInput() throws Exception
{
}
/**
* Enable or disable debugging
*
* @param debugging
*/
public void setDebugging(boolean debugging)
{
if (debugging)
{
Thread.setDefaultUncaughtExceptionHandler(debugAppender);
BasicConfigurator.configure(debugAppender);
}
else
{
Thread.setDefaultUncaughtExceptionHandler(null);
Logger.getRootLogger().removeAppender(debugAppender);
}
}
}
@@ -53,7 +53,8 @@
private ControlPanelFont fontPanel;
/**
* A reference to the color control panel, containing all the options for specifying the colors used in the chat view
* A reference to the color control panel, containing all the options for specifying the colors used in the chat
* view
*/
private ControlPanelColor colorPanel;
@@ -63,13 +64,21 @@
private ControlPanelMessage messagePanel;
/**
* A reference to the emoji control panel, containing all the options for whether to and how to display emoji in the chat messages
* A reference to the emoji control panel, containing all the options for whether to and how to display emoji in the
* chat messages
*/
private ControlPanelEmoji emojiPanel;
/**
* A reference to the message censorship control panel. This panel is not in a tab, but is accessible via the Message menu item. Nevertheless, it must be updated from the config objects in the same way as the tabbed control panels, so
* it is managed here in this tabs object.
* A reference to the debug control panel, hidden until selected from the Help menu option to enter debug mode,
* containing all the options for debugging
*/
private ControlPanelDebug debugPanel;
/**
* A reference to the message censorship control panel. This panel is not in a tab, but is accessible via the
* Message menu item. Nevertheless, it must be updated from the config objects in the same way as the tabbed control
* panels, so it is managed here in this tabs object.
*/
private MessageCensorPanel censorPanel;
@@ -101,6 +110,7 @@ public void build(ChatWindow chatWindow, ControlWindow ctrlWindow)
fontPanel = new ControlPanelFont(fProps, chatWindow, logBox);
messagePanel = new ControlPanelMessage(fProps, chatWindow, bot, logBox);
colorPanel = new ControlPanelColor(fProps, chatWindow, logBox);
debugPanel = new ControlPanelDebug(fProps, chatWindow);
subpanels = new ControlPanelBase[6];
@@ -113,7 +123,7 @@ public void build(ChatWindow chatWindow, ControlWindow ctrlWindow)
for (int i = 0; i < subpanels.length; i++)
{
addTab(subpanels[i].getLabel(), subpanels[i]);
addControlTab(subpanels[i]);
}
}
@@ -176,4 +186,29 @@ public void setAntiAlias(boolean antiAlias)
{
chatPanel.setAntiAlias(antiAlias);
}
public void toggleDebugTab()
{
int debugTabIndex = indexOfComponent(debugPanel);
if (debugTabIndex < 0)
{
addControlTab(debugPanel);
debugPanel.setDebugging(true);
}
else
{
removeTabAt(debugTabIndex);
debugPanel.setDebugging(false);
}
}
/**
* Adds a control panel tab to the control tabs, using its label as the tab name
*
* @param cpTab tab to add
*/
private void addControlTab(ControlPanelBase cpTab)
{
addTab(cpTab.getLabel(), cpTab);
}
}
@@ -56,6 +56,10 @@ public void log(String line)
// Blank out any time the oauth key is logged- this output might accidentally wind up in a video stream
line = line.replaceAll(authCode, blocks);
}
if (line.endsWith("\n"))
{
line = line.substring(0, line.length() - 1);
}
output.append((output.getText().isEmpty() ? "" : "\n") + line);
output.setCaretPosition(output.getDocument().getLength());
}
Oops, something went wrong.

0 comments on commit 7747cc1

Please sign in to comment.