Index: trunk/src/org/expeditee/gui/MessageBay.java
===================================================================
--- trunk/src/org/expeditee/gui/MessageBay.java	(revision 1182)
+++ trunk/src/org/expeditee/gui/MessageBay.java	(revision 1183)
@@ -35,6 +35,6 @@
 
 /**
- * The bay at the bottom of the expeditee browser which displays messages.
- * TODO: Make it thread safe!
+ * The bay at the bottom of the expeditee browser which displays messages. TODO:
+ * Make it thread safe!
  */
 public final class MessageBay {
@@ -54,6 +54,9 @@
 	/** The list of messages shown in the message bay. */
 	private static List<Item> _messages = new LinkedList<Item>();
-	
-	/** Messages which were delayed because they couldn't be shown at time of creation. */
+
+	/**
+	 * Messages which were delayed because they couldn't be shown at time of
+	 * creation.
+	 */
 	private static List<DelayedMessage> _delayedMessages = new LinkedList<DelayedMessage>();
 
@@ -86,19 +89,16 @@
 
 	/** Static-only class. */
-	private MessageBay()
-	{
-	}
-	
+	private MessageBay() {
+	}
+
 	/** Whether the message bay is ready to display messages. */
-	public static boolean isReady()
-	{
+	public static boolean isReady() {
 		return Browser.isInitComplete();
 	}
 
 	/** Syncs message bay size according to FrameGraphics max size. */
-	static void updateSize()
-	{
-		for(Item i : _messages) {
-			if(i != null) {
+	private static void updateSize() {
+		for (Item i : _messages) {
+			if (i != null) {
 				i.setOffset(0, -DisplayController.getMessageBayPaintArea().getMinY());
 			}
@@ -111,49 +111,48 @@
 
 	/** Whether the given item is an item in the message bay. */
-	public static boolean isMessageItem(Item i)
-	{
+	public static boolean isMessageItem(Item i) {
 		return _messages.contains(i) || i == _messageLink || i == _status;
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static Item getMessageLink()
-	{
+	public synchronized static Item getMessageLink() {
 		return _messageLink;
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static List<Item> getMessages()
-	{
+	public synchronized static List<Item> getMessages() {
 		return _messages;
 	}
 
 	/** Causes the entire message bay area to be invalidated. */
-	public synchronized static void invalidateFullBay()
-	{
+	public synchronized static void invalidateFullBay() {
 		DisplayController.invalidateArea(DisplayController.getMessageBayPaintArea());
 	}
 
 	/** TODO: Comment. cts16 */
-	private static void updateLink()
-	{
-		if (!isLinkInitialized && DisplayController.getFramePaintArea() != null && DisplayController.getFramePaintArea().getWidth() > 0) {
+	private static void updateLink() {
+		if (!isLinkInitialized && DisplayController.getFramePaintArea() != null
+				&& DisplayController.getFramePaintArea().getWidth() > 0) {
 			// set up 'Messages' link on the right hand side
-			_messageLink.setPosition(DisplayController.getMessageBayPaintArea().getWidth() - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X);
+			_messageLink.setPosition(DisplayController.getMessageBayPaintArea().getWidth() - MESSAGE_LINK_Y_OFFSET,
+					MESSAGE_LINK_X);
 			_messageLink.setOffset(0, -DisplayController.getMessageBayPaintArea().getMinY());
 			isLinkInitialized = true;
 		} else {
-			_messageLink.setPosition(DisplayController.getMessageBayPaintArea().getWidth() - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X);
-		}
-	}
-
-	/** TODO: Comment. cts16 */
-	public static Image getImage(Clip clip, Dimension size)
-	{
+			_messageLink.setPosition(DisplayController.getMessageBayPaintArea().getWidth() - MESSAGE_LINK_Y_OFFSET,
+					MESSAGE_LINK_X);
+		}
+	}
+
+	/** TODO: Comment. cts16 */
+	public static Image getImage(Clip clip, Dimension size) {
 		// Can't get an image with an invalid size
-		if (size == null || size.width <= 0 || size.height <= 0) return null;
+		if (size == null || size.width <= 0 || size.height <= 0) {
+			return null;
+		}
 
 		// Update the buffer
 		updateBuffer(Item.DEFAULT_BACKGROUND, clip, size);
-		
+
 		// Return the image buffer
 		return _messageBuffer;
@@ -161,6 +160,5 @@
 
 	/** Updates the image buffer to reflect the current state of the message bay. */
-	private static void updateBuffer(Colour background, Clip clip, Dimension size)
-	{
+	private synchronized static void updateBuffer(Colour background, Clip clip, Dimension size) {
 		// If the buffer doesn't exist or is the wrong size, recreate it
 		if (_messageBuffer == null || !_messageBuffer.getSize().equals(size)) {
@@ -173,12 +171,14 @@
 		g.pushDrawingSurface(_messageBuffer);
 
-		if (clip != null) g.pushClip(clip);
+		if (clip != null) {
+			g.pushClip(clip);
+		}
 		g.setAntialiasing(true);
-		
+
 		g.clear(background);
-		
+
 		g.setFont(_messageFont);
-		
-		for (Item message : _messages) {  //TODO: Solve occasional ConcurrentModificationException, possible culprit in overwriteMessage
+
+		for (Item message : _messages) {
 			if (message != null) {
 				if (clip == null || clip.isNotClipped() || message.isInDrawingArea(clip.getBounds())) {
@@ -187,31 +187,33 @@
 			}
 		}
-		
-		if (_status != null) FrameGraphics.PaintItem(_status);
+
+		if (_status != null) {
+			FrameGraphics.PaintItem(_status);
+		}
 
 		if (clip == null || clip.isNotClipped() || _messageLink.isInDrawingArea(clip.getBounds())) {
 			FrameGraphics.PaintItem(_messageLink);
 		}
-		
+
 		g.popDrawingSurface();
 	}
 
 	/** TODO: Comment. cts16 */
-	private static Text displayMessage(String message, String link, List<String> actions, Colour color)
-	{
+	private static Text displayMessage(String message, String link, List<String> actions, Colour color) {
 		return displayMessage(message, link, actions, color, true);
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static Text displayMessage(String message, String link, Colour color, boolean displayAlways, String action)
-	{
+	public synchronized static Text displayMessage(String message, String link, Colour color, boolean displayAlways,
+			String action) {
 		List<String> actions = new LinkedList<String>();
-		if (action != null) actions.add(action);
+		if (action != null) {
+			actions.add(action);
+		}
 		return displayMessage(message, link, actions, color, displayAlways);
 	}
 
 	/** TODO: Comment. cts16 */
-	private static Text newMessage(String message, String link, List<String> actions, Colour color)
-	{
+	private static Text newMessage(String message, String link, List<String> actions, Colour color) {
 		Text t = new Text(getMessagePrefix(true) + message);
 		t.setPosition(20, 15 + _messages.size() * 25);
@@ -222,18 +224,20 @@
 		t.setFont(_messageFont.clone());
 		_creator.addItem(t.copy(), true);
-		if(link == null) t.setLink(_creator.getCurrent());
+		if (link == null) {
+			t.setLink(_creator.getCurrent());
+		}
 		return t;
 	}
 
 	/** TODO: Comment. cts16 */
-	private synchronized static Text displayMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways, boolean redraw)
-	{
+	private synchronized static Text displayMessage(String message, String link, List<String> actions, Colour color,
+			boolean displayAlways, boolean redraw) {
 		assert (message != null);
-		
+
 		if (!isReady()) {
 			delayMessage(message, link, actions, color, displayAlways, redraw);
 			return null;
 		}
-		
+
 		System.out.println(message);
 
@@ -241,5 +245,7 @@
 		invalidateFullBay();
 
-		if (_suppressMessages) return null;
+		if (_suppressMessages) {
+			return null;
+		}
 
 		if (!displayAlways && message.equals(_lastMessage)) {
@@ -247,9 +253,10 @@
 			return null;
 		}
-		
+
 		_lastMessage = message;
 
 		if (_creator == null) {
-			_creator = new FrameCreator(MESSAGES_FRAMESET_NAME, FrameIO.MESSAGES_PATH, MESSAGES_FRAMESET_NAME, true, false);
+			_creator = new FrameCreator(MESSAGES_FRAMESET_NAME, FrameIO.MESSAGES_PATH, MESSAGES_FRAMESET_NAME, true,
+					false);
 		}
 
@@ -257,20 +264,20 @@
 		updateLink();
 
-		if(_messages.size() >= 3) {
+		if (_messages.size() >= 3) {
 			_messages.remove(0);
-			for(Item i : _messages) {
+			for (Item i : _messages) {
 				i.setY(i.getY() - 25);
 			}
 		}
-		
+
 		Text t = newMessage(message, link, actions, color);
-		
+
 		_messages.add(t);
-		
+
 		// update the link to the latest message frame
 		_messageLink.setLink(_creator.getCurrent());
 
 		// TODO: Can we just make this DisplayController.requestRefresh()? cts16
-		if(redraw) {
+		if (redraw) {
 			DisplayController.requestRefresh(true);
 		}
@@ -280,18 +287,16 @@
 
 	/** TODO: Comment. cts16 */
-	public synchronized static Text displayMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways)
-	{
+	public synchronized static Text displayMessage(String message, String link, List<String> actions, Colour color,
+			boolean displayAlways) {
 		return displayMessage(message, link, actions, color, displayAlways, true);
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static void overwriteMessage(String message)
-	{
+	public synchronized static void overwriteMessage(String message) {
 		overwriteMessage(message, null);
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static void overwriteMessage(String message, Colour color)
-	{
+	public synchronized static void overwriteMessage(String message, Colour color) {
 		_messages.remove(_messages.size() - 1);
 		Text t = newMessage(message, null, null, color);
@@ -301,14 +306,14 @@
 
 	/** TODO: Comment. cts16 */
-	private static String getMessagePrefix(int counter)
-	{
+	private static String getMessagePrefix(int counter) {
 		return "@" + counter + ": ";
 	}
 
 	/** TODO: Comment. cts16 */
-	private static String getMessagePrefix(boolean incrementCounter)
-	{
-		if (incrementCounter) _messageCount++;
-		
+	private static String getMessagePrefix(boolean incrementCounter) {
+		if (incrementCounter) {
+			_messageCount++;
+		}
+
 		return getMessagePrefix(_messageCount);
 	}
@@ -321,18 +326,22 @@
 	 *            the message to be displayed
 	 */
-	public synchronized static Text linkedErrorMessage(String message)
-	{
-		if (_suppressMessages) return null;
+	public synchronized static Text linkedErrorMessage(String message) {
+		if (_suppressMessages) {
+			return null;
+		}
 		Misc.beep();
 		String[] tokens = message.split(Text.FRAME_NAME_SEPARATOR);
 		String link = null;
-		if (tokens.length > 1) link = tokens[tokens.length - 1];
+		if (tokens.length > 1) {
+			link = tokens[tokens.length - 1];
+		}
 		return displayMessage(message, link, null, ERROR_COLOR);
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static Text errorMessage(String message)
-	{
-		if (_suppressMessages) return null;
+	public synchronized static Text errorMessage(String message) {
+		if (_suppressMessages) {
+			return null;
+		}
 		Misc.beep();
 		return displayMessage(message, null, null, ERROR_COLOR, false);
@@ -346,24 +355,20 @@
 	 *            The message to display to the user in the message area
 	 */
-	public synchronized static Text displayMessage(String message)
-	{
+	public synchronized static Text displayMessage(String message) {
 		return displayMessageAlways(message);
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static Text displayMessageOnce(String message)
-	{
+	public synchronized static Text displayMessageOnce(String message) {
 		return displayMessage(message, null, null, Colour.BLACK, false);
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static Text displayMessage(String message, Colour textColor)
-	{
+	public synchronized static Text displayMessage(String message, Colour textColor) {
 		return displayMessage(message, null, null, textColor);
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static Text displayMessage(Text message)
-	{
+	public synchronized static Text displayMessage(Text message) {
 		Text t = null;
 		String link = message.getLink();
@@ -377,6 +382,5 @@
 
 	/** TODO: Comment. cts16 */
-	public synchronized static Text displayMessageAlways(String message)
-	{
+	public synchronized static Text displayMessageAlways(String message) {
 		return displayMessage(message, null, null, Colour.BLACK);
 		// Misc.Beep();
@@ -384,27 +388,27 @@
 
 	/** TODO: Comment. cts16 */
-	public synchronized static Text warningMessage(String message)
-	{
+	public synchronized static Text warningMessage(String message) {
 		return displayMessage(message, null, null, Colour.MAGENTA);
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static List<Text> warningMessages(List<String> messages)
-	{
-		if (messages == null) return null;
+	public synchronized static List<Text> warningMessages(List<String> messages) {
+		if (messages == null) {
+			return null;
+		}
 		List<Text> ret = new LinkedList<Text>();
-		for (String message : messages) ret.add(warningMessage(message));
+		for (String message : messages) {
+			ret.add(warningMessage(message));
+		}
 		return ret;
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static void suppressMessages(boolean val)
-	{
+	public synchronized static void suppressMessages(boolean val) {
 		_suppressMessages = val;
 	}
 
 	/** TODO: Comment. cts16 */
-	public synchronized static void setStatus(String status)
-	{
+	public synchronized static void setStatus(String status) {
 		if (_status == null) {
 			_status = new Text(status);
@@ -417,29 +421,31 @@
 		}
 
-		//invalidateFullBay();
+		// invalidateFullBay();
 		DisplayController.requestRefresh(true);
 	}
 
 	/** TODO: Comment. cts16 */
-	public static final class Progress
-	{
+	public static final class Progress {
 		/** The colour progress bars should be displayed in. */
 		private static final Colour BAR_COLOUR = Colour.GREEN.darker();
-		
-		/** The character used to assemble the uncompleted portions of the progress bar. */
+
+		/**
+		 * The character used to assemble the uncompleted portions of the progress bar.
+		 */
 		private static final char UNCOMPLETED_CHARACTER = '\u2591'; // ░
-		/** The character used to assemble the completed portions of the progress bar. */
+		/**
+		 * The character used to assemble the completed portions of the progress bar.
+		 */
 		private static final char COMPLETED_CHARACTER = '\u2592'; // ▒
-		
+
 		/** What the progress bar should look like when at 100% completion. */
 		private static final String COMPLETED_BAR = Util.nCopiesOf(20, COMPLETED_CHARACTER);
 		/** What the progress bar should look like when at 0% completion. */
 		private static final String UNCOMPLETED_BAR = Util.nCopiesOf(20, UNCOMPLETED_CHARACTER);
-		
+
 		private String _message;
 		private Text _text;
-		
-		protected Progress(String text)
-		{
+
+		protected Progress(String text) {
 			this._text = displayMessage(text, null, null, BAR_COLOUR, true, false);
 			this._message = this._text.getText();
@@ -447,44 +453,46 @@
 			DisplayController.requestRefresh(true);
 		}
-		
-		public void UpdateMessage(final String text, final int newProgress) throws Exception
-		{
+
+		public void UpdateMessage(final String text, final int newProgress) throws Exception {
 			this._message = text;
 			set(newProgress);
 		}
-		
-		public String GetMessage()
-		{
+
+		public String GetMessage() {
 			return _message;
 		}
-		
+
 		/**
 		 * 
-		 * @param progress progress value from 0 to 100
-		 * @return true if the progress was updated, false if the progress was off the screen
-		 * @throws Exception if progress out of bounds
+		 * @param progress
+		 *            progress value from 0 to 100
+		 * @return true if the progress was updated, false if the progress was off the
+		 *         screen
+		 * @throws Exception
+		 *             if progress out of bounds
 		 */
-		public boolean set(int progress) throws Exception
-		{
-			if(progress < 0 || progress > 100) throw new Exception("Progress value out of bounds");
+		public boolean set(int progress) throws Exception {
+			if (progress < 0 || progress > 100) {
+				throw new Exception("Progress value out of bounds");
+			}
 			int p = progress / 5;
-			if(isMessageItem(this._text)) {
-				this._text.setText(this._message + " [" + COMPLETED_BAR.substring(0, p) + UNCOMPLETED_BAR.substring(p) + "] " + progress + "%");
+			if (isMessageItem(this._text)) {
+				this._text.setText(this._message + " [" + COMPLETED_BAR.substring(0, p) + UNCOMPLETED_BAR.substring(p)
+						+ "] " + progress + "%");
 				DisplayController.requestRefresh(true);
 				return true;
 			}
-    		return false;
-    	}
-	}
-
-	/** TODO: Comment. cts16 */
-	public synchronized static Progress displayProgress(String message)
-	{
+			return false;
+		}
+	}
+
+	/** TODO: Comment. cts16 */
+	public synchronized static Progress displayProgress(String message) {
 		return new Progress(message);
 	}
-	
-	/** Remembers the arguments to a displayMessage call for later use. */ 
+
+	/** Remembers the arguments to a displayMessage call for later use. */
 	private static class DelayedMessage {
-		
+
 		private String _message;
 		private String _link;
@@ -493,7 +501,7 @@
 		private boolean _displayAlways;
 		private boolean _redraw;
-		
-		public DelayedMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways, boolean redraw)
-		{
+
+		public DelayedMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways,
+				boolean redraw) {
 			_message = message;
 			_link = link;
@@ -501,5 +509,5 @@
 				_actions = null;
 			} else {
-				_actions =  new LinkedList<String>();
+				_actions = new LinkedList<String>();
 				_actions.addAll(actions);
 			}
@@ -508,24 +516,26 @@
 			_redraw = redraw;
 		}
-		
-		public void display()
-		{
+
+		public void display() {
 			displayMessage(_message, _link, _actions, _colour, _displayAlways, _redraw);
 		}
-		
-	}
-	
-	private static void delayMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways, boolean redraw)
-	{
+
+	}
+
+	private static void delayMessage(String message, String link, List<String> actions, Colour color,
+			boolean displayAlways, boolean redraw) {
 		_delayedMessages.add(new DelayedMessage(message, link, actions, color, displayAlways, redraw));
 	}
-	
-	public static void showDelayedMessages()
-	{
+
+	public static void showDelayedMessages(final boolean requestRefresh) {
 		if (isReady()) {
-			for (DelayedMessage message : _delayedMessages) message.display();
+			for (DelayedMessage message : _delayedMessages) {
+				message.display();
+			}
 			_delayedMessages.clear();
 			invalidateFullBay();
-			DisplayController.requestRefresh(true);
+			if(requestRefresh) {
+				DisplayController.requestRefresh(true);
+			}
 		}
 	}
