import java.awt.Component;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

@SuppressWarnings("unused")
public class PairingListCellRenderer implements ListCellRenderer<Pairing> {
	
	@Override
	public Component getListCellRendererComponent(JList<? extends Pairing> list, Pairing value, int index, boolean isSelected, boolean cellHasFocus) {
		
		String latex = "?";
		
		if (value != null) {
			
			String type = value.getVariableExpression().getType().toString();
			
			if (value.isPaired()) {
				//make a copy of the expression so that any selections can be removed,
				//otherwise the selected subexpression will show as highlighted in the pairings list.
				Expression copy = value.getPairedExpression().duplicate();
				copy.deselectRecursive();
				latex = type + " " + value.getVariableExpression().toLatex() + " \\leftarrow " + copy.toLatex();
				//latex = value.getVariableExpression().toLatex() + " \\leftarrow " + value.getPairedExpression().toLatex();
			}
			else {
				latex = type + " " + value.getVariableExpression().toLatex() + " \\textrm{ is unpaired}";
			}
			
			if (isSelected) {
	            latex = "\\bgcolor{" + LookAndFeel.SELECTED_LATEX_COLOR + "}{" + latex + "}";
			}
		}
		
		return new JLabel(new ImageIcon(LatexHandler.latexToImage(latex)));
	}
}
@@ -24,46 +24,8 @@
 nt;%0A
-import java.awt.image.BufferedImage;%0A%0A
 impo
@@ -145,36 +145,8 @@
 r;%0A%0A
-@SuppressWarnings(%22unused%22)%0A
 publ
@@ -807,198 +807,126 @@
 x = 
-type + %22 %22 + value.getVariableExpression().toLatex() + %22 %5C%5Cleftarrow %22 + copy.toLatex();%0A%09%09%09%09//latex = value.getVariableExpression().toLatex() + %22 %5C%5Cleftarrow %22 + value.getPairedExpression()
+String.format(%22%5C%5Ctextrm%7B%25s %7D %25s %5C%5Cleftarrow %25s%22,%0A%09%09%09%09%09%09type,%0A%09%09%09%09%09%09value.getVariableExpression().toLatex(),%0A%09%09%09%09%09%09copy
 .toL
@@ -931,16 +931,17 @@
 oLatex()
+)
 ;%0A%09%09%09%7D%0A%09
@@ -965,21 +965,83 @@
 x = 
-type + %22 %22 + 
+String.format(%22%5C%5Ctextrm%7B%25s %7D %25s %5C%5Ctextrm%7B is unpaired%7D%22,%0A%09%09%09%09%09%09type,%0A%09%09%09%09%09%09
 valu
@@ -1079,36 +1079,9 @@
 ex()
- + %22 %5C%5Ctextrm%7B is unpaired%7D%22
+)
 ;%0A%09%09
@@ -1105,18 +1105,16 @@
 elected)
- %7B
 %0A%09      
@@ -1131,23 +1131,58 @@
 x = 
-%22%5C%5Cbgcolor%7B%22 + 
+String.format(%22%5C%5Cbgcolor%7B%25s%7D%7B%25s%7D%22,%0A%09            %09%09
 Look
@@ -1213,35 +1213,32 @@
 OLOR
- + %22%7D%7B%22 + latex + %22%7D%22;%0A%09%09%09%7D
+,%0A%09            %09%09latex);
 %0A%09%09%7D

Improve output for Pairing lists