package nxm.sys.test;

import nxm.sys.lib.*;

import java.awt.Component;
import javax.swing.*;
import javax.swing.table.*;

/** A sample cell renderer used with LIST2.
    @author  J. Czechowski IV
    @version $Id: BackwardsTextCellRenderer.java,v 1.3 2015/05/18 12:50:25 paq Exp $
    @since   NeXtMidas 2.3.1
 */
@SuppressWarnings("serial")
public class BackwardsTextCellRenderer extends DefaultTableCellRenderer implements TableCellRenderer {
  /** The Midas context to use */
  private Midas midas;

  /** Creates a new instance of SampleCellRenderer
      @param midas Expects a Midas object to be passed in
  */
  public BackwardsTextCellRenderer(Midas midas) {
    this.midas = midas;
  }

  @Override
  public Component getTableCellRendererComponent(JTable table, Object val, boolean sel,
                                                 boolean focus, int row, int col) {
    Component comp = super.getTableCellRendererComponent(table,val,sel,focus,row,col);

    if (comp instanceof BackwardsTextCellRenderer) { // Almost always true.
      BackwardsTextCellRenderer scr = (BackwardsTextCellRenderer)comp;

      StringBuffer str = new StringBuffer();
      str.append(val);
      str.reverse();

      scr.setText(str.toString());
    }
    return comp;
  }
}
