fang
Class ErrorConsole

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Dialog
                  extended by javax.swing.JDialog
                      extended by fang.ErrorConsole
All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class ErrorConsole
extends JDialog
implements ActionListener

Displays runtime errors in a meaningful way.

Author:
Jam Jenkins
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JDialog
JDialog.AccessibleJDialog
 
Nested classes/interfaces inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Method Summary
 void actionPerformed(ActionEvent e)
          advances to the next error and makes this gui invisible when there are no more errors
static void addError(String diagnosis, String fix, Throwable e)
          sets the content of the window displaying the error screen.
static void addUnknownError(Throwable e)
          call this method for errors which should not occur.
static String fixedWidth(String text)
          makes the text monospaced in html
static String fixHTML(String text)
          replaces the symbols less than, greater than, quotes, new lines, spaces, and tabs with the corresponding html to display these properly.
static StackTraceElement getErrorElement(Throwable t)
          iterates through the execution stack to find the first element which is outside of the FANG Engine
static String getErrorFile(Throwable t)
          gets the name of the source file where the error occurred
static String getErrorLine(Throwable t)
          gets the text of the line where the error occurred
static int getErrorLineNumber(Throwable t)
          gets the line number where the error occurred
static String getErrorMethod(Throwable t)
          gets the name of the method where the error occurred
static String getLine(String fileName, int lineNumber)
          gets the line of the file where the error is.
static String getLocationSection(Throwable e)
          gets the text for displaying the error's location
static String heading(String text)
          makes the text large
static String indent(String text)
          indents the given text 40 pixels
static void registerExceptionHandler()
          this catches uncaught exceptions when the game runs as an application.
static String subHeading(String text)
          makes the text slightly smaller than the heading
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Dialog
addNotify, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

actionPerformed

public void actionPerformed(ActionEvent e)
advances to the next error and makes this gui invisible when there are no more errors

Specified by:
actionPerformed in interface ActionListener
See Also:
ActionListener.actionPerformed(java.awt.event.ActionEvent)

getLine

public static String getLine(String fileName,
                             int lineNumber)
gets the line of the file where the error is. This reads from the file until a semicolon is found.

Parameters:
fileName - the name of the file to read from
lineNumber - the line to return the contents of
Returns:
the statement starting at the given line

fixHTML

public static String fixHTML(String text)
replaces the symbols less than, greater than, quotes, new lines, spaces, and tabs with the corresponding html to display these properly.

Parameters:
text - the text to convert, usually Java code
Returns:
the html for displaying the text properly

fixedWidth

public static String fixedWidth(String text)
makes the text monospaced in html

Parameters:
text - the text to make monospaced, typically file names and code
Returns:
text surrounded with a tag to make it monospaced

indent

public static String indent(String text)
indents the given text 40 pixels

Parameters:
text - the string to indent
Returns:
text surrounded with a tag to indent it 40 pixels

heading

public static String heading(String text)
makes the text large

Parameters:
text - the heading
Returns:
text surrounded with a tag for making it large

subHeading

public static String subHeading(String text)
makes the text slightly smaller than the heading

Parameters:
text - the subheading
Returns:
text surrounded with a tag for making it large

getLocationSection

public static String getLocationSection(Throwable e)
gets the text for displaying the error's location

Parameters:
e - the exception that generated the error
Returns:
detailed information about where the error occurred

getErrorLine

public static String getErrorLine(Throwable t)
gets the text of the line where the error occurred

Returns:
the line of the error ending in a semicolon

getErrorLineNumber

public static int getErrorLineNumber(Throwable t)
gets the line number where the error occurred

Returns:
the line number

getErrorMethod

public static String getErrorMethod(Throwable t)
gets the name of the method where the error occurred

Returns:
the method name

getErrorFile

public static String getErrorFile(Throwable t)
gets the name of the source file where the error occurred

Returns:
the file name of the code with the error in it

getErrorElement

public static StackTraceElement getErrorElement(Throwable t)
iterates through the execution stack to find the first element which is outside of the FANG Engine

Returns:
the stack trace element of the code with the error

addError

public static void addError(String diagnosis,
                            String fix,
                            Throwable e)
sets the content of the window displaying the error screen. If more than one error occurs, this adds the error to the queue.

Parameters:
title - the title of the JDialog box
content - the content of the help

addUnknownError

public static void addUnknownError(Throwable e)
call this method for errors which should not occur. If they do occur, the FANG Engine developers need to know about it.

Parameters:
e - the unexpected exception

registerExceptionHandler

public static void registerExceptionHandler()
this catches uncaught exceptions when the game runs as an application. The primary uncaught exceptions are initializer errors in games run as applications. Unfortunately, nothing can detect initializer errors in applets very well.