Index: trunk/src/org/expeditee/items/Text.java
===================================================================
--- trunk/src/org/expeditee/items/Text.java	(revision 1047)
+++ trunk/src/org/expeditee/items/Text.java	(revision 1095)
@@ -129,7 +129,7 @@
 
 	/*
-	 * Set the width to be IMPLICIT, but as wide as possible, a negative width
-	 * value is one that is implicitly set by the system... a positive value is
-	 * one explicitly set by the user.
+	 * Set the width to be IMPLICIT, but as wide as possible, a negative width value
+	 * is one that is implicitly set by the system... a positive value is one
+	 * explicitly set by the user.
 	 */
 	private Integer _maxWidth = Integer.MIN_VALUE + 1;
@@ -149,5 +149,5 @@
 
 	private int _selectionEnd = -1;
-	
+
 	// whether autowrap is on/off for this item
 	protected boolean _autoWrap = false;
@@ -165,8 +165,6 @@
 	// The font to display this text in
 	private Font _font;
-	
-	
-	protected static void InitFontFamily(GraphicsEnvironment ge, File fontFamilyDir)
-	{
+
+	protected static void InitFontFamily(GraphicsEnvironment ge, File fontFamilyDir) {
 		File[] fontFiles = fontFamilyDir.listFiles();
 
@@ -179,5 +177,5 @@
 
 			if (i > p) {
-				ext = fileName.substring(i+1);
+				ext = fileName.substring(i + 1);
 			}
 
@@ -187,34 +185,32 @@
 					Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
 
-					boolean registered_status_ok= ge.registerFont(font);
+					boolean registered_status_ok = ge.registerFont(font);
 
 					if (registered_status_ok) {
-					    
-					    String font_family = font.getFamily();
-					    if (!FONT_WHEEL_ADDITIONAL_LOOKUP.containsKey(font_family)) {
-
-						if (FONT_WHEEL_ADDITIONAL_LOOKUP.size()>0) {
-						    System.out.print(", ");
+
+						String font_family = font.getFamily();
+						if (!FONT_WHEEL_ADDITIONAL_LOOKUP.containsKey(font_family)) {
+
+							if (FONT_WHEEL_ADDITIONAL_LOOKUP.size() > 0) {
+								System.out.print(", ");
+							}
+							System.out.print("'" + font.getFamily() + "'");
+
+							FONT_WHEEL_ADDITIONAL_LOOKUP.put(font_family, font);
+
+							int cdut = font.canDisplayUpTo("09AZaz");
+							if (cdut >= 0) {
+								// Some problem has occured (should return -1 to show all chars possible)
+
+								System.out.println(" [Non-ASCII font]");
+							}
+							System.out.flush();
 						}
-						System.out.print("'" + font.getFamily() + "'");
-
-						FONT_WHEEL_ADDITIONAL_LOOKUP.put(font_family,font);
-											    
-						int cdut = font.canDisplayUpTo("09AZaz");
-						if (cdut>=0) {
-						    // Some problem has occured (should return -1 to show all chars possible)
-						
-						    System.out.println(" [Non-ASCII font]");
-						}
-						System.out.flush();
-					    }
-						
+
+					} else {
+						System.err.println("Error: Failed to add custom True-Type Font file: " + fontFile);
 					}
-					else {
-					    System.err.println("Error: Failed to add custom True-Type Font file: " + fontFile);
-					}
-										
-				}
-				catch (Exception e) {
+
+				} catch (Exception e) {
 					System.err.println("Failed to load custon font file: " + fontFile);
 				}
@@ -222,7 +218,7 @@
 		}
 	}
-	
+
 	public static void InitFonts() {
-		
+
 		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 
@@ -234,19 +230,18 @@
 				if (fontFamilyDirs != null) {
 
-					if (fontFamilyDirs.length>0) {
+					if (fontFamilyDirs.length > 0) {
 						System.out.println("Loading custom fonts:");
 					}
 
-					boolean first_item = true;		
+					boolean first_item = true;
 					for (File fontFamilyDir : fontFamilyDirs) {
 						if (fontFamilyDir.isDirectory()) {
-							InitFontFamily(ge,fontFamilyDir);
+							InitFontFamily(ge, fontFamilyDir);
 						}
 					}
-					System.out.println();	  
+					System.out.println();
 				}
 			}
-		}
-		else {
+		} else {
 			System.err.println("No graphics environment detected.  Skipping the loading of the custom fonts");
 		}
@@ -254,74 +249,74 @@
 
 	/**
-     * Similar to parseArgs() in InteractiveWidget.  
-     * Code based on routine used in Apache Ant:
-     *   org.apache.tools.ant.types.Commandline::translateCommandline()
-     * @param toProcess the command line to process.
-     * @return the command line broken into strings.
-     * An empty or null toProcess parameter results in a zero sized array.
-     */
-    public static String[] parseArgsApache(String toProcess) {
-        if (toProcess == null || toProcess.length() == 0) {
-            //no command? no string
-            return new String[0];
-        }
-        // parse with a simple finite state machine
-
-        final int normal = 0;
-        final int inQuote = 1;
-        final int inDoubleQuote = 2;
-        int state = normal;
-        final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
-        final ArrayList<String> result = new ArrayList<String>();
-        final StringBuilder current = new StringBuilder();
-        boolean lastTokenHasBeenQuoted = false;
-
-        while (tok.hasMoreTokens()) {
-            String nextTok = tok.nextToken();
-            switch (state) {
-            case inQuote:
-                if ("\'".equals(nextTok)) {
-                    lastTokenHasBeenQuoted = true;
-                    state = normal;
-                } else {
-                    current.append(nextTok);
-                }
-                break;
-            case inDoubleQuote:
-                if ("\"".equals(nextTok)) {
-                    lastTokenHasBeenQuoted = true;
-                    state = normal;
-                } else {
-                    current.append(nextTok);
-                }
-                break;
-            default:
-                if ("\'".equals(nextTok)) {
-                    state = inQuote;
-                } else if ("\"".equals(nextTok)) {
-                    state = inDoubleQuote;
-                } else if (" ".equals(nextTok)) {
-                    if (lastTokenHasBeenQuoted || current.length() != 0) {
-                        result.add(current.toString());
-                        current.setLength(0);
-                    }
-                } else {
-                    current.append(nextTok);
-                }
-                lastTokenHasBeenQuoted = false;
-                break;
-            }
-        }
-        if (lastTokenHasBeenQuoted || current.length() != 0) {
-            result.add(current.toString());
-        }
-        if (state == inQuote || state == inDoubleQuote) {
-	    System.err.println("Error: Unbalanced quotes -- failed to parse '" + toProcess + "'");
-	    return null;
-        }
-
-        return result.toArray(new String[result.size()]);
-    }
-
+	 * Similar to parseArgs() in InteractiveWidget. Code based on routine used in
+	 * Apache Ant: org.apache.tools.ant.types.Commandline::translateCommandline()
+	 * 
+	 * @param toProcess
+	 *            the command line to process.
+	 * @return the command line broken into strings. An empty or null toProcess
+	 *         parameter results in a zero sized array.
+	 */
+	public static String[] parseArgsApache(String toProcess) {
+		if (toProcess == null || toProcess.length() == 0) {
+			// no command? no string
+			return new String[0];
+		}
+		// parse with a simple finite state machine
+
+		final int normal = 0;
+		final int inQuote = 1;
+		final int inDoubleQuote = 2;
+		int state = normal;
+		final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
+		final ArrayList<String> result = new ArrayList<String>();
+		final StringBuilder current = new StringBuilder();
+		boolean lastTokenHasBeenQuoted = false;
+
+		while (tok.hasMoreTokens()) {
+			String nextTok = tok.nextToken();
+			switch (state) {
+			case inQuote:
+				if ("\'".equals(nextTok)) {
+					lastTokenHasBeenQuoted = true;
+					state = normal;
+				} else {
+					current.append(nextTok);
+				}
+				break;
+			case inDoubleQuote:
+				if ("\"".equals(nextTok)) {
+					lastTokenHasBeenQuoted = true;
+					state = normal;
+				} else {
+					current.append(nextTok);
+				}
+				break;
+			default:
+				if ("\'".equals(nextTok)) {
+					state = inQuote;
+				} else if ("\"".equals(nextTok)) {
+					state = inDoubleQuote;
+				} else if (" ".equals(nextTok)) {
+					if (lastTokenHasBeenQuoted || current.length() != 0) {
+						result.add(current.toString());
+						current.setLength(0);
+					}
+				} else {
+					current.append(nextTok);
+				}
+				lastTokenHasBeenQuoted = false;
+				break;
+			}
+		}
+		if (lastTokenHasBeenQuoted || current.length() != 0) {
+			result.add(current.toString());
+		}
+		if (state == inQuote || state == inDoubleQuote) {
+			System.err.println("Error: Unbalanced quotes -- failed to parse '" + toProcess + "'");
+			return null;
+		}
+
+		return result.toArray(new String[result.size()]);
+	}
 
 	/**
@@ -371,10 +366,10 @@
 
 	/**
-	 * Sets the maximum width of this Text item when justifcation is used.
-	 * passing in 0 or -1 means there is no maximum width
+	 * Sets the maximum width of this Text item when justifcation is used. passing
+	 * in 0 or -1 means there is no maximum width
 	 * 
 	 * @param width
-	 *            The maximum width of this item when justification is applied
-	 *            to it.
+	 *            The maximum width of this item when justification is applied to
+	 *            it.
 	 */
 	@Override
@@ -394,6 +389,6 @@
 
 	/**
-	 * Returns the maximum width of this Text item when justifcation is used. If
-	 * the width is negative, it means no explicit width has been set
+	 * Returns the maximum width of this Text item when justifcation is used. If the
+	 * width is negative, it means no explicit width has been set
 	 * 
 	 * @return The maximum width of this Text item when justification is used
@@ -422,6 +417,6 @@
 
 	/**
-	 * Sets the justification of this Text item. The given integer should
-	 * correspond to one of the JUSTIFICATION constants defined in Item
+	 * Sets the justification of this Text item. The given integer should correspond
+	 * to one of the JUSTIFICATION constants defined in Item
 	 * 
 	 * @param just
@@ -443,6 +438,6 @@
 
 	/**
-	 * Returns the current justification of this Text item. The default value
-	 * left justification.
+	 * Returns the current justification of this Text item. The default value left
+	 * justification.
 	 * 
 	 * @return The justification of this Text item
@@ -464,6 +459,6 @@
 
 	/**
-	 * Sets the text displayed on the screen to the given String. It does not
-	 * reset the formula, attributeValuePair or other cached values.
+	 * Sets the text displayed on the screen to the given String. It does not reset
+	 * the formula, attributeValuePair or other cached values.
 	 * 
 	 * @param text
@@ -481,6 +476,5 @@
 
 		/*
-		 * Always clearingCach remove formulas when moving in and out of XRay
-		 * mode
+		 * Always clearingCach remove formulas when moving in and out of XRay mode
 		 */
 		if (clearCache) {
@@ -520,6 +514,5 @@
 
 	/**
-	 * Inserts the given String at the start of the first line of this Text
-	 * Item.
+	 * Inserts the given String at the start of the first line of this Text Item.
 	 * 
 	 * @param text
@@ -533,6 +526,6 @@
 
 	/**
-	 * If the first line of text starts with the given String, then it is
-	 * removed otherwise no action is taken.
+	 * If the first line of text starts with the given String, then it is removed
+	 * otherwise no action is taken.
 	 * 
 	 * @param text
@@ -586,5 +579,5 @@
 
 		_text.append(text);
-		
+
 		rebuild(true);
 	}
@@ -595,6 +588,5 @@
 	 * @param text
 	 *            The prefix to check for
-	 * @return True if the first line starts with the given String, False
-	 *         otherwise.
+	 * @return True if the first line starts with the given String, False otherwise.
 	 */
 	public boolean startsWith(String text) {
@@ -607,6 +599,5 @@
 
 		if (ignoreCase)
-			return _text.toString().toLowerCase()
-					.startsWith(text.toLowerCase());
+			return _text.toString().toLowerCase().startsWith(text.toLowerCase());
 		else
 			return _text.indexOf(text) == 0;
@@ -668,6 +659,5 @@
 	private Point2D.Float getEdgePosition(int line, boolean start) {
 		// if there is no text yet, or the line is invalid
-		if (_text == null || _text.length() == 0 || line < 0
-				|| line > _textLayouts.size() - 1)
+		if (_text == null || _text.length() == 0 || line < 0 || line > _textLayouts.size() - 1)
 			return new Point2D.Float(getX(), getY());
 
@@ -684,8 +674,5 @@
 
 		float x = getX() + caret[0] + getJustOffset(last);
-		x = Math
-				.min(
-						x,
-						(getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
+		x = Math.min(x, (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
 		return new Point2D.Float(x, getY() + y + caret[1]);
 	}
@@ -728,6 +715,5 @@
 			_selectionEnd = _text.length();
 
-		return _text.substring(Math.min(_selectionStart, _selectionEnd), Math
-				.max(_selectionStart, _selectionEnd));
+		return _text.substring(Math.min(_selectionStart, _selectionEnd), Math.max(_selectionStart, _selectionEnd));
 	}
 
@@ -787,6 +773,6 @@
 
 	/**
-	 * Inserts the given String into the Text at the position given by the
-	 * mouseX and mouseY coordinates
+	 * Inserts the given String into the Text at the position given by the mouseX
+	 * and mouseY coordinates
 	 * 
 	 * @param text
@@ -803,6 +789,5 @@
 	}
 
-	public Point2D.Float insertText(String text, float mouseX, float mouseY,
-			int insertPos) {
+	public Point2D.Float insertText(String text, float mouseX, float mouseY, int insertPos) {
 		TextHitInfo hit;
 		TextLayout current = null;
@@ -874,14 +859,11 @@
 					}
 					// Check if there is a space after the bullet
-					if (index < _text.length() - 1
-							&& _text.charAt(index + 1) == ' ') {
+					if (index < _text.length() - 1 && _text.charAt(index + 1) == ' ') {
 						// Change the bullet
-						_text.setCharAt(index, getPreviousBullet(_text
-								.charAt(index)));
+						_text.setCharAt(index, getPreviousBullet(_text.charAt(index)));
 					}
 					// Remove the spacing at the start
 					for (int i = 0; i < TAB_STRING.length(); i++) {
-						if (_text.length() > 0
-								&& Character.isSpaceChar(_text.charAt(0))) {
+						if (_text.length() > 0 && Character.isSpaceChar(_text.charAt(0))) {
 							deleteChar(0);
 							pos--;
@@ -898,6 +880,5 @@
 					}
 					// Check if there is a space after the bullet
-					if (index < _text.length() - 1
-							&& _text.charAt(index + 1) == ' ') {
+					if (index < _text.length() - 1 && _text.charAt(index + 1) == ' ') {
 						char nextBullet = getNextBullet(_text.charAt(index));
 						// Change the bullet
@@ -954,13 +935,9 @@
 
 		float x = getX() + caret[0] + getJustOffset(current);
-		x = Math
-				.min(
-						x,
-						(getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
+		x = Math.min(x, (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
 
 		invalidateAll();
 
-		return new Point2D.Float(Math.round(x), Math.round(getY() + y
-				+ caret[1]));
+		return new Point2D.Float(Math.round(x), Math.round(getY() + y + caret[1]));
 	}
 
@@ -986,6 +963,6 @@
 	}
 
-	public Point2D.Float moveCursor(int direction, float mouseX, float mouseY,
-			boolean setSelection, boolean wholeWord) {
+	public Point2D.Float moveCursor(int direction, float mouseX, float mouseY, boolean setSelection,
+			boolean wholeWord) {
 		if (setSelection) {
 			if (!hasSelection()) {
@@ -1047,12 +1024,9 @@
 							// Keep going if the char to the left is a
 							// letterOrDigit
-							prevChar = _text.charAt(hit.getInsertionIndex() - 1
-									+ _lineOffsets.get(line));
-						} while (wholeWord
-								&& Character.isLetterOrDigit(prevChar));
+							prevChar = _text.charAt(hit.getInsertionIndex() - 1 + _lineOffsets.get(line));
+						} while (wholeWord && Character.isLetterOrDigit(prevChar));
 						// TODO Go to the start of the word instead of before
 						// the word
-						char nextChar = _text.charAt(hit.getInsertionIndex()
-								+ _lineOffsets.get(line));
+						char nextChar = _text.charAt(hit.getInsertionIndex() + _lineOffsets.get(line));
 						/*
 						 * This takes care of hard line break in
@@ -1061,35 +1035,25 @@
 							line--;
 							hit = _textLayouts.get(line)
-									.getNextRightHit(
-											_textLayouts.get(line)
-													.getCharacterCount() - 1);
+									.getNextRightHit(_textLayouts.get(line).getCharacterCount() - 1);
 						}
 						// This takes care of soft line breaks.
 					} else if (line > 0) {
 						line--;
-						hit = _textLayouts.get(line).getNextRightHit(
-								_textLayouts.get(line).getCharacterCount() - 1);
+						hit = _textLayouts.get(line).getNextRightHit(_textLayouts.get(line).getCharacterCount() - 1);
 						/*
-						 * Skip the spaces at the end of a line with soft
-						 * linebreak
+						 * Skip the spaces at the end of a line with soft linebreak
 						 */
 						while (hit.getCharIndex() > 0
-								&& _text.charAt(_lineOffsets.get(line)
-										+ hit.getCharIndex() - 1) == ' ') {
+								&& _text.charAt(_lineOffsets.get(line) + hit.getCharIndex() - 1) == ' ') {
 							hit = _textLayouts.get(line).getNextLeftHit(hit);
 						}
 					}
 				} else if (direction == RIGHT) {
-					if (hit.getInsertionIndex() < _textLayouts.get(line)
-							.getCharacterCount()) {
+					if (hit.getInsertionIndex() < _textLayouts.get(line).getCharacterCount()) {
 						hit = _textLayouts.get(line).getNextRightHit(hit);
 						// Skip whole word if needs be
-						while (wholeWord
-								&& hit.getCharIndex() > 0
-								&& hit.getCharIndex() < _textLayouts.get(line)
-										.getCharacterCount()
-								&& Character.isLetterOrDigit(_text
-										.charAt(_lineOffsets.get(line)
-												+ hit.getCharIndex() - 1)))
+						while (wholeWord && hit.getCharIndex() > 0
+								&& hit.getCharIndex() < _textLayouts.get(line).getCharacterCount() && Character
+										.isLetterOrDigit(_text.charAt(_lineOffsets.get(line) + hit.getCharIndex() - 1)))
 							hit = _textLayouts.get(line).getNextRightHit(hit);
 					} else if (line < _textLayouts.size() - 1) {
@@ -1105,6 +1069,5 @@
 			float y = getLineDrop(current) * line;
 
-			resultPos = new Point2D.Float(getX() + caret[0]
-					+ getJustOffset(current), getY() + y + caret[1]);
+			resultPos = new Point2D.Float(getX() + caret[0] + getJustOffset(current), getY() + y + caret[1]);
 			break;
 		}
@@ -1142,10 +1105,8 @@
 		for (TextLayout text : _textLayouts) {
 			// calculate X to ensure it is in the shape
-			Rectangle2D bounds = text.getLogicalHighlightShape(0,
-					text.getCharacterCount()).getBounds2D();
+			Rectangle2D bounds = text.getLogicalHighlightShape(0, text.getCharacterCount()).getBounds2D();
 
 			if (bounds.getWidth() < 1)
-				bounds.setRect(bounds.getMinX(), bounds.getMinY(), 10, bounds
-						.getHeight());
+				bounds.setRect(bounds.getMinX(), bounds.getMinY(), 10, bounds.getHeight());
 
 			double x = bounds.getCenterX();
@@ -1202,8 +1163,7 @@
 
 	public void setFamily(String newFamily) {
-		String toDecode = newFamily + "-" + getFontStyle() + "-"
-				+ Math.round(getSize());
+		String toDecode = newFamily + "-" + getFontStyle() + "-" + Math.round(getSize());
 		setFont(Font.decode(toDecode));
-		
+
 		setLetterSpacing(this._letter_spacing);
 	}
@@ -1228,10 +1188,11 @@
 
 	public static final String[] FONT_WHEEL = { "sansserif", "monospaced", "serif", "dialog", "dialoginput" };
-	public static final char[]   FONT_CHARS = { 's', 'm', 't', 'd', 'i' };
-
-        // A hashtable to store the font family names that are loaded in through the TTF files
-        // provided in the 'assets' folder
-        public static HashMap<String, Font> FONT_WHEEL_ADDITIONAL_LOOKUP = new HashMap<>();
-    
+	public static final char[] FONT_CHARS = { 's', 'm', 't', 'd', 'i' };
+
+	// A hashtable to store the font family names that are loaded in through the TTF
+	// files
+	// provided in the 'assets' folder
+	public static HashMap<String, Font> FONT_WHEEL_ADDITIONAL_LOOKUP = new HashMap<>();
+
 	private static final int NEARBY_GRAVITY = 2;
 
@@ -1308,6 +1269,6 @@
 		} else if (newFace.equals("italic") || newFace.equals("i")) {
 			setFont(getPaintFont().deriveFont(Font.ITALIC));
-		} else if (newFace.equals("bolditalic") || newFace.equals("italicbold")
-				|| newFace.equals("bi") || newFace.equals("ib")) {
+		} else if (newFace.equals("bolditalic") || newFace.equals("italicbold") || newFace.equals("bi")
+				|| newFace.equals("ib")) {
 			setFont(getPaintFont().deriveFont(Font.BOLD + Font.ITALIC));
 		}
@@ -1335,7 +1296,5 @@
 			for (int offset : _lineOffsets) {
 				if (offset != last) {
-					list
-							.add(_text.substring(last, offset).replaceAll("\n",
-									""));
+					list.add(_text.substring(last, offset).replaceAll("\n", ""));
 				}
 				last = offset;
@@ -1399,6 +1358,5 @@
 	private float getLineDrop(TextLayout layout) {
 		if (getSpacing() < 0)
-			return layout.getAscent() + layout.getDescent()
-					+ layout.getLeading();
+			return layout.getAscent() + layout.getDescent() + layout.getLeading();
 
 		return layout.getAscent() + layout.getDescent() + getSpacing();
@@ -1417,5 +1375,6 @@
 	 * 
 	 * @param spacing
-	 *            Additional spacing to add between letters. See {@link java.awt.font.TextAttribute#TRACKING}
+	 *            Additional spacing to add between letters. See
+	 *            {@link java.awt.font.TextAttribute#TRACKING}
 	 */
 	public void setLetterSpacing(float spacing) {
@@ -1423,5 +1382,5 @@
 		HashMap<TextAttribute, Object> attr = new HashMap<TextAttribute, Object>();
 		attr.put(TextAttribute.TRACKING, spacing);
-		
+
 		if (this._font == null) {
 			this._font = Font.decode(DEFAULT_FONT);
@@ -1432,5 +1391,6 @@
 
 	/**
-	 * @return The spacing (proportional to the font size) between letters. See {@link java.awt.font.TextAttribute#TRACKING}
+	 * @return The spacing (proportional to the font size) between letters. See
+	 *         {@link java.awt.font.TextAttribute#TRACKING}
 	 */
 	public float getLetterSpacing() {
@@ -1446,5 +1406,5 @@
 	}
 
-	//@Override
+	// @Override
 	public boolean intersectsOLD(Polygon p) {
 		if (super.intersects(p)) {
@@ -1453,11 +1413,7 @@
 			for (TextLayout text : _textLayouts) {
 				// check left and right of each box
-				Rectangle2D textOutline = text.getLogicalHighlightShape(0,
-						text.getCharacterCount()).getBounds2D();
-				textOutline
-						.setRect(textOutline.getX() + getX() - 1, textOutline
-								.getY()
-								+ textY - 1, textOutline.getWidth() + 2,
-								textOutline.getHeight() + 2);
+				Rectangle2D textOutline = text.getLogicalHighlightShape(0, text.getCharacterCount()).getBounds2D();
+				textOutline.setRect(textOutline.getX() + getX() - 1, textOutline.getY() + textY - 1,
+						textOutline.getWidth() + 2, textOutline.getHeight() + 2);
 				if (p.intersects(textOutline))
 					return true;
@@ -1467,15 +1423,16 @@
 		return false;
 	}
-	
-	// The following version of intersect uses a tighter definition for the text, based on 
-    @Override
+
+	// The following version of intersect uses a tighter definition for the text,
+	// based on
+	@Override
 	public boolean intersects(Polygon p) {
 		if (super.intersects(p)) {
-//			float textY = getY();
+			// float textY = getY();
 
 			for (TextLayout text : _textLayouts) {
-				
+
 				Rectangle text_pixel_bounds_rect = this.getPixelBounds(text);
-				
+
 				if (p.intersects(text_pixel_bounds_rect)) {
 					return true;
@@ -1483,5 +1440,5 @@
 			}
 		}
-		
+
 		return false;
 	}
@@ -1502,6 +1459,5 @@
 
 		// Check if its outside the top and left and bottom bounds
-		if (outline.getX() - mouseX > gravity
-				|| outline.getY() - mouseY > gravity
+		if (outline.getX() - mouseX > gravity || outline.getY() - mouseY > gravity
 				|| mouseY - (outline.getY() + outline.getHeight()) > gravity
 				|| mouseX - (outline.getX() + outline.getWidth()) > gravity) {
@@ -1511,6 +1467,5 @@
 		for (TextLayout text : _textLayouts) {
 			// check left and right of each box
-			Rectangle2D textOutline = text.getLogicalHighlightShape(0,
-					text.getCharacterCount()).getBounds2D();
+			Rectangle2D textOutline = text.getLogicalHighlightShape(0, text.getCharacterCount()).getBounds2D();
 
 			// check if the cursor is within the top, bottom and within the
@@ -1518,9 +1473,6 @@
 			int justOffset = getJustOffset(text);
 
-			if (mouseY - textY > textOutline.getY()
-					&& mouseY - textY < textOutline.getY()
-							+ textOutline.getHeight()
-					&& mouseX - textX - justOffset < textOutline.getWidth()
-							+ gravity + Item.MARGIN_RIGHT
+			if (mouseY - textY > textOutline.getY() && mouseY - textY < textOutline.getY() + textOutline.getHeight()
+					&& mouseX - textX - justOffset < textOutline.getWidth() + gravity + Item.MARGIN_RIGHT
 			/* &&(justOffset == 0 || mouseX > textX + justOffset - gravity ) */)
 				return true;
@@ -1555,15 +1507,14 @@
 
 		float y = -1;
-		
+
 		// Fix concurrency error in ScaleFrameset
 		List<TextLayout> tmpTextLayouts;
-		synchronized(_textLayouts) {
+		synchronized (_textLayouts) {
 			tmpTextLayouts = new LinkedList<TextLayout>(_textLayouts);
 		}
 
 		for (TextLayout layout : tmpTextLayouts) {
-			Rectangle2D bounds = layout.getLogicalHighlightShape(0,
-					layout.getCharacterCount()).getBounds2D();
-		
+			Rectangle2D bounds = layout.getLogicalHighlightShape(0, layout.getCharacterCount()).getBounds2D();
+
 			if (y < 0)
 				y = 0;
@@ -1591,8 +1542,10 @@
 
 		_poly.translate(getX(), getY());
-						
-		if(preChangeWidth != 0 && preChangeWidth != _poly.getBounds().width) 
-			if(_poly.getBounds().width > preChangeWidth) MagneticConstraints.getInstance().textGrown(this, _poly.getBounds().width - preChangeWidth);
-			else MagneticConstraints.getInstance().textShrunk(this, preChangeWidth - _poly.getBounds().width);
+
+		if (preChangeWidth != 0 && preChangeWidth != _poly.getBounds().width)
+			if (_poly.getBounds().width > preChangeWidth)
+				MagneticConstraints.getInstance().textGrown(this, _poly.getBounds().width - preChangeWidth);
+			else
+				MagneticConstraints.getInstance().textShrunk(this, preChangeWidth - _poly.getBounds().width);
 	}
 
@@ -1630,6 +1583,5 @@
 
 		if (_lineBreaker == null || newLinebreakerAlways) {
-			AttributedString paragraphText = new AttributedString(_text
-					.toString());
+			AttributedString paragraphText = new AttributedString(_text.toString());
 			paragraphText.addAttribute(TextAttribute.FONT, getPaintFont());
 			frc = new FontRenderContext(null, true, true);
@@ -1637,12 +1589,10 @@
 		}
 
-		/* float width = Float.MAX_VALUE;
-
-		if (limitWidth) {
-			width = getAbsoluteWidth();
-			// else if (getMaxWidth() > 0)
-			// width = Math.max(50, getMaxWidth() - getX()
-			// - Item.MARGIN_RIGHT);
-		} */
+		/*
+		 * float width = Float.MAX_VALUE;
+		 * 
+		 * if (limitWidth) { width = getAbsoluteWidth(); // else if (getMaxWidth() > 0)
+		 * // width = Math.max(50, getMaxWidth() - getX() // - Item.MARGIN_RIGHT); }
+		 */
 
 		_textLayouts.clear();
@@ -1652,45 +1602,49 @@
 
 		TextLayout layout;
-		
+
 		float width;
 		float lineHeight = Float.NaN;
 		List<Point[]> lines = null;
-		
-		if(_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
-		lines = new LinkedList<Point[]>();
-    		if(DisplayIO.getCurrentFrame() == null) {
-    			return;
-    		}
-    		for(Item item : DisplayIO.getCurrentFrame().getItems()) {
-    				if(item instanceof Line) {
-    					lines.add(new Point[] { ((Line) item).getStartItem().getPosition(), ((Line) item).getEndItem().getPosition() });
-    				}
-    				if(item instanceof Picture) {
-    					lines.add(new Point[] { item.getPosition(), new Point(item.getX(), item.getY() + item.getHeight()) });
-    				}
-    		}
-    		for(Item item : FreeItems.getInstance()) {
-    				if(item instanceof Line) {
-    					lines.add(new Point[] { ((Line) item).getStartItem().getPosition(), ((Line) item).getEndItem().getPosition() });
-    				}
-    				if(item instanceof Picture) {
-    					lines.add(new Point[] { item.getPosition(), new Point(item.getX(), item.getY() + item.getHeight()) });
-    				}
-    		}
-    		width = getLineWidth(getX(), getY(), lines);
+
+		if (_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
+			lines = new LinkedList<Point[]>();
+			if (DisplayIO.getCurrentFrame() == null) {
+				return;
+			}
+			for (Item item : DisplayIO.getCurrentFrame().getItems()) {
+				if (item instanceof Line) {
+					lines.add(new Point[] { ((Line) item).getStartItem().getPosition(),
+							((Line) item).getEndItem().getPosition() });
+				}
+				if (item instanceof Picture) {
+					lines.add(
+							new Point[] { item.getPosition(), new Point(item.getX(), item.getY() + item.getHeight()) });
+				}
+			}
+			for (Item item : FreeItems.getInstance()) {
+				if (item instanceof Line) {
+					lines.add(new Point[] { ((Line) item).getStartItem().getPosition(),
+							((Line) item).getEndItem().getPosition() });
+				}
+				if (item instanceof Picture) {
+					lines.add(
+							new Point[] { item.getPosition(), new Point(item.getX(), item.getY() + item.getHeight()) });
+				}
+			}
+			width = getLineWidth(getX(), getY(), lines);
 		} else {
 			width = Float.MAX_VALUE;
-     		if (limitWidth) {
-     			if(_maxWidth == null) {
-     				width = FrameGraphics.getMaxFrameSize().width - getX();
-     			} else {
-     				width = getAbsoluteWidth();
-     			}
-     			// else if (getMaxWidth() > 0)
-     			// width = Math.max(50, getMaxWidth() - getX()
-     			// - Item.MARGIN_RIGHT);
-     		}
-		}
-		
+			if (limitWidth) {
+				if (_maxWidth == null) {
+					width = FrameGraphics.getMaxFrameSize().width - getX();
+				} else {
+					width = getAbsoluteWidth();
+				}
+				// else if (getMaxWidth() > 0)
+				// width = Math.max(50, getMaxWidth() - getX()
+				// - Item.MARGIN_RIGHT);
+			}
+		}
+
 		_lineBreaker.setPosition(0);
 		boolean requireNextWord = false;
@@ -1698,17 +1652,17 @@
 		// --- Get the output of the LineBreakMeasurer and store it in a
 		while (_lineBreaker.getPosition() < _text.length()) {
-			
-			if(_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
+
+			if (_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
 				requireNextWord = width < FrameGraphics.getMaxFrameSize().width - getX();
 			}
-			
+
 			layout = _lineBreaker.nextLayout(width, _text.length(), requireNextWord);
-			
+
 			// lineBreaker does not break on newline
 			// characters so they have to be check manually
 			int start = _lineOffsets.get(_lineOffsets.size() - 1);
-			
-			// int y = getY() + (getLineDrop(layout) * (_lineOffsets.size() - 1) 
-			
+
+			// int y = getY() + (getLineDrop(layout) * (_lineOffsets.size() - 1)
+
 			// check through the current line for newline characters
 			for (int i = start + 1; i < _text.length(); i++) {
@@ -1721,6 +1675,6 @@
 
 			_lineOffsets.add(_lineBreaker.getPosition());
-			
-			if(layout == null) {
+
+			if (layout == null) {
 				layout = new TextLayout(" ", getPaintFont(), frc);
 			}
@@ -1729,13 +1683,13 @@
 					&& _lineBreaker.getPosition() < _text.length())
 				layout = layout.getJustifiedLayout(width);
-			
+
 			_textLayouts.add(layout);
-    						
-			if(_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
-				
-    			if(lineHeight != Float.NaN) {
-    				lineHeight = getLineDrop(layout);
-    			}
-    			width = getLineWidth(getX(), getY() + (lineHeight * (_textLayouts.size() - 1)), lines);
+
+			if (_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
+
+				if (lineHeight != Float.NaN) {
+					lineHeight = getLineDrop(layout);
+				}
+				width = getLineWidth(getX(), getY() + (lineHeight * (_textLayouts.size() - 1)), lines);
 			}
 		}
@@ -1744,16 +1698,16 @@
 
 	}
-	
+
 	private float getLineWidth(int x, float y, List<Point[]> lines) {
 		float width = FrameGraphics.getMaxFrameSize().width;
-		for(Point[] l : lines) {
+		for (Point[] l : lines) {
 			// check for lines that cross over our y
-			if((l[0].y >= y && l[1].y <= y) || (l[0].y <= y && l[1].y >= y)) {
+			if ((l[0].y >= y && l[1].y <= y) || (l[0].y <= y && l[1].y >= y)) {
 				float dX = l[0].x - l[1].x;
 				float dY = l[0].y - l[1].y;
 				float newWidth;
-				if(dX == 0) {
+				if (dX == 0) {
 					newWidth = l[0].x;
-				} else if(dY == 0) {
+				} else if (dY == 0) {
 					newWidth = Math.min(l[0].x, l[1].x);
 				} else {
@@ -1762,8 +1716,8 @@
 				}
 				// System.out.println("dY:" + dY + " dX:" + dX + " width:" + newWidth);
-				if(newWidth < x) {
-				 	continue;
+				if (newWidth < x) {
+					continue;
 				}
-				if(newWidth < width) {
+				if (newWidth < width) {
 					width = newWidth;
 				}
@@ -1807,6 +1761,5 @@
 		// if the selection is before this line, return null
 		if (_lineOffsets.get(line) < selectionLeft
-				&& _lineOffsets.get(line)
-						+ _textLayouts.get(line).getCharacterCount() < selectionLeft)
+				&& _lineOffsets.get(line) + _textLayouts.get(line).getCharacterCount() < selectionLeft)
 			return null;
 
@@ -1820,6 +1773,5 @@
 		// int end = Math.min(_lineOffsets.get(line) +
 		// _textLayouts.get(line).getCharacterCount(), _selectionEnd);
-		int end = Math.min(selectionRight - _lineOffsets.get(line),
-				+_textLayouts.get(line).getCharacterCount());
+		int end = Math.min(selectionRight - _lineOffsets.get(line), +_textLayouts.get(line).getCharacterCount());
 
 		// System.out.println(line + ": " + start + "x" + end + " (" +
@@ -1840,12 +1792,10 @@
 		 * Color main = getPaintColor(); Color back = getPaintBackgroundColor();
 		 * 
-		 * if (Math.abs(main.getRed() - back.getRed()) < 10 &&
-		 * Math.abs(main.getGreen() - back.getGreen()) < 10 &&
-		 * Math.abs(main.getBlue() - back.getBlue()) < 10) { selection = new
-		 * Color(Math.abs(255 - main.getRed()), Math .abs(255 -
-		 * main.getGreen()), Math.abs(255 - main.getBlue())); } else { selection =
-		 * new Color((main.getRed() + (back.getRed() * 2)) / 3, (main.getGreen() +
-		 * (back.getGreen() * 2)) / 3, (main .getBlue() + (back.getBlue() * 2)) /
-		 * 3); }
+		 * if (Math.abs(main.getRed() - back.getRed()) < 10 && Math.abs(main.getGreen()
+		 * - back.getGreen()) < 10 && Math.abs(main.getBlue() - back.getBlue()) < 10) {
+		 * selection = new Color(Math.abs(255 - main.getRed()), Math .abs(255 -
+		 * main.getGreen()), Math.abs(255 - main.getBlue())); } else { selection = new
+		 * Color((main.getRed() + (back.getRed() * 2)) / 3, (main.getGreen() +
+		 * (back.getGreen() * 2)) / 3, (main .getBlue() + (back.getBlue() * 2)) / 3); }
 		 */
 		int green = 160;
@@ -1876,8 +1826,8 @@
 		if (_text == null || _text.length() == 0)
 			return;
-		
-		if(_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
+
+		if (_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
 			invalidateAll();
-		
+
 			rebuild(true);
 		} else if (_textLayouts.size() < 1) {
@@ -1901,6 +1851,5 @@
 			Color bgc = getBackgroundColor();
 			if (_alpha > 0) {
-				bgc = new Color(bgc.getRed(), bgc.getGreen(), bgc.getBlue(),
-						_alpha);
+				bgc = new Color(bgc.getRed(), bgc.getGreen(), bgc.getBlue(), _alpha);
 			}
 			g.setColor(bgc);
@@ -1912,6 +1861,5 @@
 				if (s != null) {
 					Rectangle b = s.getBounds();
-					GradientPaint gp = new GradientPaint(
-							(int) (b.x + b.width * 0.3), b.y, bgc,
+					GradientPaint gp = new GradientPaint((int) (b.x + b.width * 0.3), b.y, bgc,
 							(int) (b.x + b.width * 1.3), b.y, gradientColor);
 					g.setPaint(gp);
@@ -1936,12 +1884,10 @@
 			Point2D.Float start = getEdgePosition(0, true);
 			Point2D.Float end = getEdgePosition(0, false);
-			g.drawLine(Math.round(start.x), Math.round(start.y), Math
-					.round(end.x), Math.round(end.y));
+			g.drawLine(Math.round(start.x), Math.round(start.y), Math.round(end.x), Math.round(end.y));
 		}
 
 		if (isHighlighted()) {
 			g.setColor(getPaintHighlightColor());
-			Stroke highlightStroke = new BasicStroke(
-					(float) getHighlightThickness(), CAP, JOIN);
+			Stroke highlightStroke = new BasicStroke((float) getHighlightThickness(), CAP, JOIN);
 			g.setStroke(highlightStroke);
 			if (HighlightMode.Enclosed.equals(getHighlightMode()))
@@ -1958,6 +1904,5 @@
 		g.setColor(c);
 
-		Color selection = getSelectionColor(FrameMouseActions
-				.getLastMouseButton());
+		Color selection = getSelectionColor(FrameMouseActions.getLastMouseButton());
 
 		// width -= getX();
@@ -1982,26 +1927,24 @@
 				}
 
-				int ldx = 1+getX()+getJustOffset(layout); // Layout draw x
-				
+				int ldx = 1 + getX() + getJustOffset(layout); // Layout draw x
+
 				boolean debug = false;
 				if (debug) {
-					g.setColor(new Color(c.getRed(),c.getGreen(),c.getBlue(),40));
+					g.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 40));
 					Rectangle layout_rect = layout.getPixelBounds(null, ldx, y);
 					g.fillRect(layout_rect.x, layout_rect.y, layout_rect.width, layout_rect.height);
 					g.setColor(c);
 				}
-				
-				
+
 				layout.draw(g, ldx, y);
 
 				/*
-				 * AffineTransform at = new AffineTransform(); AffineTransform
-				 * orig = g.getTransform(); at.translate(getX() +
-				 * getJustOffset(layout), y); g.setTransform(at);
-				 * g.draw(layout.getLogicalHighlightShape(0,
+				 * AffineTransform at = new AffineTransform(); AffineTransform orig =
+				 * g.getTransform(); at.translate(getX() + getJustOffset(layout), y);
+				 * g.setTransform(at); g.draw(layout.getLogicalHighlightShape(0,
 				 * layout.getCharacterCount())); g.setTransform(orig); /*
-				 * if(_text.charAt(_lineOffsets.get(line) +
-				 * (layout.getCharacterCount() - 1)) == '\t'){ tab = true; x =
-				 * (int) (getX() + x + 20 + layout.getVisibleAdvance()); }else{
+				 * if(_text.charAt(_lineOffsets.get(line) + (layout.getCharacterCount() - 1)) ==
+				 * '\t'){ tab = true; x = (int) (getX() + x + 20 + layout.getVisibleAdvance());
+				 * }else{
 				 */
 				y += getLineDrop(layout);
@@ -2097,12 +2040,8 @@
 			if (isAnnotation())
 				return;
-			if (!isLineEnd() && _text.length() > 0
-					&& _text.charAt(0) == DEFAULT_BULLET) {
-				newPoint.setLocation(insertText(""
-						+ (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1));
+			if (!isLineEnd() && _text.length() > 0 && _text.charAt(0) == DEFAULT_BULLET) {
+				newPoint.setLocation(insertText("" + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1));
 				if (_text.length() > 0 && _text.charAt(0) == ' ')
-					newPoint.setLocation(insertText(""
-							+ (char) KeyEvent.VK_BACK_SPACE, newPoint.x,
-							newPoint.y, 1));
+					newPoint.setLocation(insertText("" + (char) KeyEvent.VK_BACK_SPACE, newPoint.x, newPoint.y, 1));
 			} else {
 				newPoint.setLocation(insertText("@", mouseX, mouseY, 0));
@@ -2113,11 +2052,8 @@
 				return;
 			if (!isLineEnd() && _text.charAt(0) == '@') {
-				newPoint.setLocation(insertText(""
-						+ (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1));
-				newPoint.setLocation(insertText(DEFAULT_BULLET_STRING,
-						newPoint.x, newPoint.y, 0));
+				newPoint.setLocation(insertText("" + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1));
+				newPoint.setLocation(insertText(DEFAULT_BULLET_STRING, newPoint.x, newPoint.y, 0));
 			} else {
-				newPoint.setLocation(insertText(""
-						+ (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1));
+				newPoint.setLocation(insertText("" + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1));
 			}
 		}
@@ -2178,9 +2114,7 @@
 		String s = _text.toString().toLowerCase();
 		if (s.length() > 0 && s.indexOf("@") == 0) {
-			if (s.equals("@old") || s.equals("@ao")
-					|| s.equals("@itemtemplate") || s.equals("@parent")
-					|| s.equals("@next") || s.equals("@previous")
-					|| s.equals("@first") || s.equals("@i") || s.equals("@iw")
-					|| s.equals("@f"))
+			if (s.equals("@old") || s.equals("@ao") || s.equals("@itemtemplate") || s.equals("@parent")
+					|| s.equals("@next") || s.equals("@previous") || s.equals("@first") || s.equals("@i")
+					|| s.equals("@iw") || s.equals("@f"))
 				return true;
 		}
@@ -2245,6 +2179,5 @@
 			setRightMargin(modelFrame.getNameItem().getX() - MARGIN_LEFT, true);
 		} else {
-			System.out
-					.print("Error: text.resetTitlePosition, getParent or currentFrame returned null");
+			System.out.print("Error: text.resetTitlePosition, getParent or currentFrame returned null");
 			setRightMargin(MARGIN_LEFT, true);
 		}
@@ -2283,11 +2216,12 @@
 		Text template = this.copy();
 		template.setID(-1);
-		// reset width of global templates so the widths of the items on the settings frames don't cause issues
-		// this is in response to the fact that FrameCreator.addItem() sets rightMargin when it adds items
+		// reset width of global templates so the widths of the items on the settings
+		// frames don't cause issues
+		// this is in response to the fact that FrameCreator.addItem() sets rightMargin
+		// when it adds items
 		template.setWidth(null);
 		/*
-		 * The template must have text otherwise the bounds height will be
-		 * zero!! This will stop escape drop down from working if there is no
-		 * item template
+		 * The template must have text otherwise the bounds height will be zero!! This
+		 * will stop escape drop down from working if there is no item template
 		 */
 		template.setText("@");
@@ -2308,12 +2242,10 @@
 			for (TextLayout text : _textLayouts) {
 				// check left and right of each box
-				Rectangle2D textOutline = text.getLogicalHighlightShape(0,
-						text.getCharacterCount()).getBounds2D();
+				Rectangle2D textOutline = text.getLogicalHighlightShape(0, text.getCharacterCount()).getBounds2D();
 
 				// check if the cursor is within the top, bottom and within the
 				// gravity of right
 				if (y - textY > textOutline.getY() - NEAR_DISTANCE
-						&& y - textY < textOutline.getY()
-								+ textOutline.getHeight() + NEAR_DISTANCE
+						&& y - textY < textOutline.getY() + textOutline.getHeight() + NEAR_DISTANCE
 						&& x - textX < textOutline.getWidth() + NEAR_DISTANCE)
 					return true;
@@ -2342,11 +2274,10 @@
 		}
 	}
-	
+
 	private void clipFrameMargin() {
 		if (!hasFixedWidth()) {
 			int frameWidth = FrameGraphics.getMaxFrameSize().width;
 			/*
-			 * Only change width if it is more than 150 pixels from the right of
-			 * the screen
+			 * Only change width if it is more than 150 pixels from the right of the screen
 			 */
 			if (!_text.toString().contains(" ")) {
@@ -2360,11 +2291,11 @@
 		}
 	}
-	
+
 	public void justify(boolean fixWidth, Polygon enclosure) {
 		// if autowrap is on, wrapping is done every time we draw
-		if(ExperimentalFeatures.AutoWrap.get()) {
+		if (ExperimentalFeatures.AutoWrap.get()) {
 			return;
 		}
-		
+
 		Integer width = FrameGraphics.getMaxFrameSize().width;
 
@@ -2384,6 +2315,5 @@
 		// on the frame
 		String widthString;
-		if ((widthString = getParentOrCurrentFrame().getAnnotationValue(
-				"maxwidth")) != null) {
+		if ((widthString = getParentOrCurrentFrame().getAnnotationValue("maxwidth")) != null) {
 			try {
 				int oldWidth = getWidth();
@@ -2399,5 +2329,5 @@
 	public void justify(boolean fixWidth) {
 		// if autowrap is on, wrapping is done every time we draw
-		if(ExperimentalFeatures.AutoWrap.get()) {
+		if (ExperimentalFeatures.AutoWrap.get()) {
 			return;
 		}
@@ -2452,6 +2382,5 @@
 		if (!text.startsWith("@"))
 			return false;
-		return text.startsWith("@o") || text.startsWith("@ao")
-				|| text.startsWith("@v") || text.startsWith("@av");
+		return text.startsWith("@o") || text.startsWith("@ao") || text.startsWith("@v") || text.startsWith("@av");
 	}
 
@@ -2505,5 +2434,5 @@
 					}
 				} // else {
-				// Add anonomous vars
+					// Add anonomous vars
 				try {
 					double value = pair.getDoubleValue();
@@ -2528,6 +2457,5 @@
 			// If the frame is linked add vector variable for the frame
 			if (lowercaseFormula.contains("$frame")) {
-				myParser.addVectorVariable(frame.getNonAnnotationItems(true),
-						"$frame");
+				myParser.addVectorVariable(frame.getNonAnnotationItems(true), "$frame");
 			}
 		}
@@ -2553,5 +2481,5 @@
 			}
 		} catch (Throwable e) {
-			//e.printStackTrace();
+			// e.printStackTrace();
 			String formula2 = getFormula();
 			this.setText(formula2);
@@ -2566,8 +2494,7 @@
 
 	/**
-	 * Gets items which are in the same enclosure as this item. 
-	 * In the event more than one enclosure meets this criteria, then
-	 * the one returned is the one with the smallest area.
-	 * TODO: Improve the efficiency of this method
+	 * Gets items which are in the same enclosure as this item. In the event more
+	 * than one enclosure meets this criteria, then the one returned is the one with
+	 * the smallest area. TODO: Improve the efficiency of this method
 	 * 
 	 * @return
@@ -2580,6 +2507,5 @@
 		for (Item i : parent.getVisibleItems()) {
 			/*
-			 * Go through all the enclosures looking for one that includes this
-			 * item
+			 * Go through all the enclosures looking for one that includes this item
 			 */
 			if (!seen.contains(i) && i.isEnclosed()) {
@@ -2589,6 +2515,5 @@
 				// Check it is smaller than any other enclosure found containing
 				// this item
-				if (enclosed.contains(this)
-						&& i.getEnclosedArea() < enclosureArea) {
+				if (enclosed.contains(this) && i.getEnclosedArea() < enclosureArea) {
 					sameEnclosure = enclosed;
 				}
@@ -2601,8 +2526,8 @@
 		return sameEnclosure;
 	}
-	
-	/**
-	 * Returns true if items of the parent frame should be recalculated when
-	 * this item is modified
+
+	/**
+	 * Returns true if items of the parent frame should be recalculated when this
+	 * item is modified
 	 */
 	public boolean recalculateWhenChanged() {
@@ -2639,8 +2564,8 @@
 		invalidateFill();
 		invalidateCommonTrait(ItemAppearence.PreMoved);
-		
+
 		this._anchorLeft = anchor;
 		this._anchorRight = null;
-		
+
 		int oldX = getX();
 		if (anchor != null) {
@@ -2659,6 +2584,5 @@
 			// Subtract off the link width
 			if (anchor != null) {
-				setX(FrameGraphics.getMaxFrameSize().width - anchor
-						- getBoundsWidth() + getLeftMargin());
+				setX(FrameGraphics.getMaxFrameSize().width - anchor - getBoundsWidth() + getLeftMargin());
 			}
 			return;
@@ -2666,12 +2590,11 @@
 		invalidateFill();
 		invalidateCommonTrait(ItemAppearence.PreMoved);
-		
+
 		this._anchorRight = anchor;
 		this._anchorLeft = null;
-		
+
 		int oldX = getX();
 		if (anchor != null) {
-			float deltaX = FrameGraphics.getMaxFrameSize().width - anchor
-					- getBoundsWidth() + getLeftMargin() - oldX;
+			float deltaX = FrameGraphics.getMaxFrameSize().width - anchor - getBoundsWidth() + getLeftMargin() - oldX;
 			anchorConnected(AnchorEdgeType.Right, deltaX);
 		}
@@ -2680,6 +2603,4 @@
 		invalidateFill();
 	}
-
-
 
 	@Override
@@ -2694,8 +2615,8 @@
 		invalidateFill();
 		invalidateCommonTrait(ItemAppearence.PreMoved);
-		
+
 		this._anchorTop = anchor;
 		this._anchorBottom = null;
-		
+
 		int oldY = getY();
 		if (anchor != null) {
@@ -2713,5 +2634,6 @@
 			super.setAnchorBottom(anchor);
 			if (anchor != null) {
-				setY(FrameGraphics.getMaxFrameSize().height - (anchor + this.getBoundsHeight() - _textLayouts.get(0).getAscent() - _textLayouts.get(0).getDescent()));
+				setY(FrameGraphics.getMaxFrameSize().height - (anchor + this.getBoundsHeight()
+						- _textLayouts.get(0).getAscent() - _textLayouts.get(0).getDescent()));
 			}
 			return;
@@ -2719,8 +2641,8 @@
 		invalidateFill();
 		invalidateCommonTrait(ItemAppearence.PreMoved);
-		
+
 		this._anchorBottom = anchor;
 		this._anchorTop = null;
-		
+
 		int oldY = getY();
 		if (anchor != null) {
@@ -2742,66 +2664,125 @@
 			setWidth(Math.round(width * scale));
 		}
-		
+
 		super.scale(scale, originX, originY);
 		rebuild(true);
 	}
 
-	
-	protected Rectangle getPixelBounds(TextLayout layout)
-	{
+	protected Rectangle getPixelBounds(TextLayout layout) {
 		// Does 'layout' need to be synchronized (similar to _textLayouts below)??
 		int x = getX();
 		int y = getY();
 
-		int ldx = 1+x+getJustOffset(layout); // Layout draw x				
+		int ldx = 1 + x + getJustOffset(layout); // Layout draw x
 		Rectangle layout_rect = layout.getPixelBounds(null, ldx, y);
 
-		return layout_rect;		
-	}
-	
-	
-	public Rectangle getPixelBoundsUnion()
-	{
-		synchronized (_textLayouts) {
-			
-			int x = getX();
-			int y = getY();
-	
-			int min_xl = Integer.MAX_VALUE;
-			int max_xr = Integer.MIN_VALUE;
-	
-			int min_yt = Integer.MAX_VALUE;
-			int max_yb = Integer.MIN_VALUE;
-		
-			
-			for (int i = 0; i < _textLayouts.size(); i++) {
-				TextLayout layout = _textLayouts.get(i);
-
-				int ldx = 1+x+getJustOffset(layout); // Layout draw x				
-				Rectangle layout_rect = layout.getPixelBounds(null, ldx, y);
-					
-				int xl = layout_rect.x;
-				int xr = xl + layout_rect.width -1;
-				
-				int yt = layout_rect.y;
-				int yb = yt + layout_rect.height -1;
-				
-				min_xl = Math.min(min_xl,xl);
-				max_xr = Math.max(max_xr,xr);
-				
-				min_yt = Math.min(min_yt,yt);
-				max_yb = Math.max(max_yb,yb);
-			}
-			
-			if ((min_xl >= max_xr) || (min_yt >= max_yb)) {
-				// No valid rectangle are found
-				return null;
-			}
-			
-			return new Rectangle(min_xl,min_yt,max_xr-min_xl+1,max_yb-min_yt+1);
-			
-		}
-					
-	}
+		return layout_rect;
+	}
+
+	/**
+	 * Creates the smallest possible rectangle object to enclose the Text Item
+	 * completely. Width of the rectangle is determined by the line in the Text Item
+	 * that protrudes to the right the most. Height of the rectangle is determined
+	 * by the number of lines in the Text Item.
+	 * 
+	 * @return A rectangle enclosing the Text Item, without gravity represented.
+	 * @see #getPixelBoundsUnionTight()
+	 */
+	public Rectangle getPixelBoundsUnion() {
+		final Rectangle rect = getPixelBounds(_textLayouts.get(0));
+
+		int cumulativeHeight = rect.height;
+		int maxWidth = rect.width;
+
+		if (_textLayouts.size() > 1) {
+			for (int i = 1; i < _textLayouts.size(); i++) {
+				final Rectangle r = getPixelBounds(_textLayouts.get(i));
+				cumulativeHeight += _textLayouts.get(i).getDescent() + _textLayouts.get(i).getAscent();
+				if (r.width > maxWidth)
+					maxWidth = r.width;
+			}
+		}
+
+		rect.setSize(maxWidth, cumulativeHeight);
+
+		return rect;
+	}
+
+	/**
+	 * Creates the smallest possible polygon to enclose the Text Item completely.
+	 * The shape of the polygon is determined by the length of each line, tightly
+	 * fitting the shape so that no white space is inside the resulting polygon.
+	 * 
+	 * @return A polygon enclosing the Text Item, without gravity represented.
+	 * @see #getPixelBoundsUnion()
+	 */
+	public Polygon getPixelBoundsUnionTight() {
+		final Rectangle rect = getPixelBounds(_textLayouts.get(0));
+		if (_textLayouts.size() == 1) {
+			int x = (int) rect.getX();
+			int y = (int) rect.getY();
+			return new Polygon(new int[] { x, x + rect.width, x + rect.width, x },
+					new int[] { y, y, y + rect.height, y + rect.height }, 4);
+		} else {
+			final Polygon poly = new Polygon();
+			poly.addPoint(rect.x, rect.y);
+			poly.addPoint(rect.x + rect.width, rect.y);
+			poly.addPoint(rect.x + rect.width, Math.round(rect.y + rect.height + _textLayouts.get(0).getDescent()));
+			int y = (int) (rect.y + rect.height + _textLayouts.get(0).getDescent());
+			for (int i = 1; i < _textLayouts.size(); i++) {
+				final Rectangle r = getPixelBounds(_textLayouts.get(i));
+				poly.addPoint(r.x + r.width, y);
+				poly.addPoint(r.x + r.width, Math.round(y + r.height + _textLayouts.get(i).getDescent()));
+				y = Math.round(y + r.height + _textLayouts.get(i).getDescent());
+			}
+			poly.addPoint(rect.x + getPixelBounds(_textLayouts.get(_textLayouts.size() - 1)).width, Math.round(y + _textLayouts.get(_textLayouts.size() - 1).getDescent()));
+			poly.addPoint(rect.x, Math.round(y + _textLayouts.get(_textLayouts.size() - 1).getDescent()));
+			return poly;
+		}
+	}
+
+	// public Rectangle getPixelBoundsUnion()
+	// {
+	// synchronized (_textLayouts) {
+	//
+	// int x = getX();
+	// int y = getY();
+	//
+	// int min_xl = Integer.MAX_VALUE;
+	// int max_xr = Integer.MIN_VALUE;
+	//
+	// int min_yt = Integer.MAX_VALUE;
+	// int max_yb = Integer.MIN_VALUE;
+	//
+	//
+	// for (int i = 0; i < _textLayouts.size(); i++) {
+	// TextLayout layout = _textLayouts.get(i);
+	//
+	// int ldx = 1+x+getJustOffset(layout); // Layout draw x
+	// Rectangle layout_rect = layout.getPixelBounds(null, ldx, y);
+	//
+	// int xl = layout_rect.x;
+	// int xr = xl + layout_rect.width -1;
+	//
+	// int yt = layout_rect.y;
+	// int yb = yt + layout_rect.height -1;
+	//
+	// min_xl = Math.min(min_xl,xl);
+	// max_xr = Math.max(max_xr,xr);
+	//
+	// min_yt = Math.min(min_yt,yt);
+	// max_yb = Math.max(max_yb,yb);
+	// }
+	//
+	// if ((min_xl >= max_xr) || (min_yt >= max_yb)) {
+	// // No valid rectangle are found
+	// return null;
+	// }
+	//
+	// return new Rectangle(min_xl,min_yt,max_xr-min_xl+1,max_yb-min_yt+1);
+	//
+	// }
+	//
+	// }
 	/*
 	 * Returns the SIMPLE statement contained by this text item.
@@ -2811,17 +2792,18 @@
 		return getText().split("\\s+")[0];
 	}
-	
+
 	public boolean getAutoWrap() {
 		return _autoWrap;
 	}
-	
-	// workaround since true is the default value and would not be displayed normally
+
+	// workaround since true is the default value and would not be displayed
+	// normally
 	public String getAutoWrapToSave() {
-		if(!_autoWrap) {
+		if (!_autoWrap) {
 			return null;
 		}
 		return "true";
 	}
-	
+
 	public void setAutoWrap(boolean autoWrap) {
 		_autoWrap = autoWrap;
