Index: /main/trunk/gli/src/org/greenstone/gatherer/cdm/Format4gs3Manager.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/cdm/Format4gs3Manager.java	(revision 29036)
+++ /main/trunk/gli/src/org/greenstone/gatherer/cdm/Format4gs3Manager.java	(revision 29037)
@@ -42,4 +42,5 @@
 import org.greenstone.gatherer.gui.GLIButton;
 import org.greenstone.gatherer.gui.FormatPane;
+import org.greenstone.gatherer.gui.NumberedJTextArea;
 import org.greenstone.gatherer.metadata.MetadataElement;
 import org.greenstone.gatherer.metadata.MetadataSetManager;
@@ -403,6 +404,4 @@
 		private JButton remove_button;
 		private JButton default_button;
-		private JButton undo_button;
-		private JButton redo_button;
 		private JComboBox feature_combobox;
 		private JList format_list;
@@ -412,5 +411,4 @@
 		private JPanel selection_pane;
 		private final Dimension FIELD_SIZE = new Dimension(200, 30);
-		private final UndoManager undo = new UndoManager();
 		private boolean newtext = true;
 		private Format4gs3 previousFormat = null;
@@ -440,22 +438,6 @@
 			JPanel editor_pane = new JPanel();
 
-			editor_textarea = new NumberedJTextArea();
-
-			/* Fields specific to RSyntaxQuery inherited class */
-			editor_textarea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
-			editor_textarea.setBracketMatchingEnabled(true);
-			editor_textarea.setAnimateBracketMatching(true);
-			editor_textarea.setAntiAliasingEnabled(true);
-			editor_textarea.setAutoIndentEnabled(true);
-			editor_textarea.setPaintMarkOccurrencesBorder(false);
-
-			/* Standard fields to JTextArea */
-			editor_textarea.setOpaque(false);
-			editor_textarea.setBackground(Configuration.getColor("coloring.editable_background", false));
-			editor_textarea.setCaretPosition(0);
-			editor_textarea.setLineWrap(true);
-			editor_textarea.setRows(11);
-			editor_textarea.setWrapStyleWord(false);
-			editor_textarea.setToolTipText(Dictionary.get("CDM.FormatManager.Add_Tooltip"));
+			// NumberedJTextArea comes with undo and redo buttons already hooked up to listeners
+			editor_textarea = new NumberedJTextArea(Dictionary.get("CDM.FormatManager.Add_Tooltip"));
 
 			default_button = new GLIButton(Dictionary.get("CDM.FormatManager.Default"), Dictionary.get("CDM.FormatManager.Default_Tooltip"));
@@ -467,26 +449,10 @@
 			remove_button.setEnabled(false);
 
-			undo_button = new GLIButton(Dictionary.get("General.Undo"), Dictionary.get("General.Undo_Tooltip"));
-			undo_button.setEnabled(false);
-
-			redo_button = new GLIButton(Dictionary.get("General.Redo"), Dictionary.get("General.Redo_Tooltip"));
-			redo_button.setEnabled(false);
-
 			// Connect
 			add_button.addActionListener(new AddListener());
 			remove_button.addActionListener(new RemoveListener());
 			default_button.addActionListener(new DefaultListener());
-			undo_button.addActionListener(new UndoListener());
-			redo_button.addActionListener(new RedoListener());
 			feature_combobox.addActionListener(new FeatureListener());
 			editor_textarea.getDocument().addDocumentListener(new EditorListener());
-			// Listen for undo and redo events
-			editor_textarea.getDocument().addUndoableEditListener(new UndoableEditListener()
-			{
-				public void undoableEditHappened(UndoableEditEvent evt)
-				{
-					undo.addEdit(evt.getEdit());
-				}
-			});
 
 			format_list.addListSelectionListener(new FormatListListener());
@@ -505,6 +471,6 @@
 			JPanel rupanel = new JPanel();
 			rupanel.setLayout(new GridLayout(1, 2));
-			rupanel.add(undo_button);
-			rupanel.add(redo_button);
+			rupanel.add(editor_textarea.undoButton);
+			rupanel.add(editor_textarea.redoButton);
 
 			editor_pane.setLayout(new BorderLayout());
@@ -651,5 +617,5 @@
 				if (!newtext)
 				{
-					undo_button.setEnabled(true);
+				    editor_textarea.undoButton.setEnabled(true);
 				}
 
@@ -694,6 +660,6 @@
 			public void actionPerformed(ActionEvent event)
 			{
-				undo_button.setEnabled(false);
-				redo_button.setEnabled(false);
+				editor_textarea.undoButton.setEnabled(false);
+				editor_textarea.redoButton.setEnabled(false);
 				default_button.setEnabled(true);
 				newtext = true;
@@ -701,5 +667,5 @@
 				if (ignore_event == true)
 				{
-					undo.discardAllEdits();
+				        editor_textarea.discardAllEdits();
 					return;
 				}
@@ -768,5 +734,5 @@
 				}
 				ignore_event = false;
-				undo.discardAllEdits();
+				editor_textarea.discardAllEdits();
 			}
 		}
@@ -776,6 +742,6 @@
 			public void valueChanged(ListSelectionEvent event)
 			{
-				undo_button.setEnabled(false);
-				redo_button.setEnabled(false);
+			        editor_textarea.undoButton.setEnabled(false);
+				editor_textarea.redoButton.setEnabled(false);
 				default_button.setEnabled(true);
 				newtext = true;
@@ -829,5 +795,5 @@
 
 				}
-				undo.discardAllEdits();
+				editor_textarea.discardAllEdits();
 			}
 
@@ -888,66 +854,4 @@
 		}
 
-		private class UndoListener implements ActionListener
-		{
-
-			public void actionPerformed(ActionEvent event)
-			{
-				try
-				{
-					if (undo.canUndo())
-					{
-						int pos = editor_textarea.getCaretPosition();
-						redo_button.setEnabled(true);
-						undo.undo();
-						if (pos > 0)
-							editor_textarea.setCaretPosition(pos - 1);
-						else
-							editor_textarea.setCaretPosition(pos);
-					}
-					if (!undo.canUndo())
-					{
-						undo_button.setEnabled(false);
-					}
-					else
-					{
-						undo_button.setEnabled(true);
-					}
-
-				}
-				catch (Exception e)
-				{
-
-				}
-			}
-		}
-
-		private class RedoListener implements ActionListener
-		{
-			public void actionPerformed(ActionEvent evt)
-			{
-				try
-				{
-					if (undo.canRedo())
-					{
-						int pos = editor_textarea.getCaretPosition();
-						undo.redo();
-						editor_textarea.setCaretPosition(pos);
-					}
-					if (!undo.canRedo())
-					{
-						redo_button.setEnabled(false);
-					}
-					else
-					{
-						redo_button.setEnabled(true);
-					}
-
-				}
-				catch (Exception e)
-				{
-				}
-			}
-		}
-
 		private void newFormat()
 		{
@@ -956,6 +860,6 @@
 			editor_textarea.setToolTipText(Dictionary.get("CDM.FormatManager.Editor_Disabled_Tooltip"));
 
-			undo_button.setEnabled(false);
-			redo_button.setEnabled(false);
+			editor_textarea.undoButton.setEnabled(false);
+			editor_textarea.redoButton.setEnabled(false);
 			add_button.setEnabled(true);
 			remove_button.setEnabled(false);
@@ -974,57 +878,4 @@
 			FormatPane.setPreviewButton(true);
 		}
-
-		/**
-		 * A textarea with the line number next to each line of the text
-		 */
-		public class NumberedJTextArea extends RSyntaxTextArea /* JTextArea */
-		{
-			public void paintComponent(Graphics g)
-			{
-				Insets insets = getInsets();
-				Rectangle rectangle = g.getClipBounds();
-				g.setColor(Color.white);
-				g.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
-
-				super.paintComponent(g);
-
-				if (rectangle.x < insets.left)
-				{
-					FontMetrics font_metrics = g.getFontMetrics();
-					int font_height = font_metrics.getHeight();
-					int y = font_metrics.getAscent() + insets.top;
-					int line_number_start_point = ((rectangle.y + insets.top) / font_height) + 1;
-					if (y < rectangle.y)
-					{
-						y = line_number_start_point * font_height - (font_height - font_metrics.getAscent());
-					}
-					int y_axis_end_point = y + rectangle.height + font_height;
-					int x_axis_start_point = insets.left;
-					x_axis_start_point -= getFontMetrics(getFont()).stringWidth(Math.max(getRows(), getLineCount() + 1) + " ");
-					if (!this.getText().trim().equals(""))
-					{
-						g.setColor(Color.DARK_GRAY);
-					}
-					else
-					{
-						g.setColor(Color.white);
-					}
-					int length = ("" + Math.max(getRows(), getLineCount() + 1)).length();
-					while (y < y_axis_end_point)
-					{
-						g.drawString(line_number_start_point + "  ", x_axis_start_point, y);
-						y += font_height;
-						line_number_start_point++;
-					}
-				}
-			}
-
-			public Insets getInsets()
-			{
-				Insets insets = super.getInsets(new Insets(0, 0, 0, 0));
-				insets.left += getFontMetrics(getFont()).stringWidth(Math.max(getRows(), getLineCount() + 1) + " ");
-				return insets;
-			}
-		}
 	}
 
