view src/MPipeline2/src/mpipeline/plisttable/JPlistDoubleRenderer.java @ 16:91f21a0aab35 database-connection-manager

Update utils.jquery * * * Update utils.jmysql.getsinfo
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line source

/*
 * Class JPlistDoubleRenderer <one line to give the program's name and a brief idea of what it does.>
 *
 * Copyright (c) 2009 Max-Planck-Gesellschaft, Martin Hewitson <martin.hewitson at aei.mpg.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
package mpipeline.plisttable;

import java.awt.Color;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Martin Hewitson <martin.hewitson at aei.mpg.de>
 */
public class JPlistDoubleRenderer extends DefaultTableCellRenderer {

  public JTextField textarea = new JTextField();
  private final static int MAX_LINES = 3;

  /**
   * Returns the component used for drawing the cell. This method is
   * used to configure the renderer appropriately before drawing.
   *
   * @param	table       the <code>JTable</code> that is asking the
   *                      renderer to draw.
   * @param	value       the value of the cell to be rendered.
   * @param	isSelected	true if the cell is to be rendered with the
   *                      selection highlighted; otherwise false
   * @param	hasFocus	if true, render cell appropriately.
   * @param	row	        the row index of the cell being drawn.
   * @param	col 	    the column index of the cell being drawn
   *
   * @return  Component
   */
  @Override
  public Component getTableCellRendererComponent(JTable table,
          Object value,
          boolean isSelected,
          boolean hasFocus,
          int row,
          int col) {

    /* Set default values from table object and UI manager*/
    if (isSelected) {
      textarea.setBackground(table.getSelectionBackground());
      textarea.setForeground(Color.blue);
    } else {
      textarea.setBackground(table.getBackground());
      textarea.setForeground(Color.blue);
    }

    textarea.setEnabled(table.isEnabled());
    textarea.setFont(table.getFont());

    if (hasFocus) {
      textarea.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
    } else {
      textarea.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    }


    textarea.setHorizontalAlignment(JTextField.RIGHT);

    /* Compute the text string */
    String str = "";
    if (value != null) {
      if (value instanceof Double) {
        str += value;
      }
    }

    textarea.setText(str);


    return textarea;
  }
}