Search in sources :

Example 1 with CTable

use of org.compiere.swing.CTable in project adempiere by adempiere.

the class VHeaderRenderer method getTableCellRendererComponent.

/**
	 *	Get TableCell RendererComponent
	 *  @param table
	 *  @param value
	 *  @param isSelected
	 *  @param hasFocus
	 *  @param row
	 *  @param column
	 *  @return Button
	 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    //  indicator for invisible column
    Icon icon = null;
    m_table = table;
    m_column = column;
    if (table instanceof CTable) {
        CTable cTable = (CTable) table;
        if (cTable.getSortColumn() == table.convertColumnIndexToModel(column)) {
            icon = cTable.isSortAscending() ? Env.getImageIcon2("uparrow") : Env.getImageIcon2("downarrow");
        }
    }
    /**
		 * If VHeaderRenderer is just created with display type as argument
		 */
    if (m_label == null && m_button == null && m_check == null) {
        TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer();
        Component headerComponent = headerRenderer == null ? null : headerRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (value == null)
            headerComponent.setPreferredSize(new Dimension(0, 0));
        if (headerComponent instanceof JLabel) {
            ((JLabel) headerComponent).setIcon(icon);
            ((JLabel) headerComponent).setHorizontalTextPosition(SwingConstants.LEADING);
        }
        return headerComponent;
    }
    /**
		 * If VHeaderRenderer has been created with GridField as argument
		 */
    if (m_button == null && m_check == null) {
        m_label.setHorizontalAlignment(m_alignment);
        if (value == null)
            m_label.setPreferredSize(new Dimension(0, 0));
        else {
            m_label.setText(value.toString());
            if (prefWidth != null && prefWidth > 0) {
                m_label.setPreferredSize(new Dimension(prefWidth, m_label.getHeight()));
                m_label.setToolTipText(value.toString());
            }
        }
        m_label.setIcon(icon);
        m_label.setHorizontalTextPosition(SwingConstants.LEADING);
        return m_label;
    }
    /**
		 * VHeaderRenderer has been created with multi-selection true
		 */
    if (m_button == null) {
        if (table != null) {
            JTableHeader header = table.getTableHeader();
            if (header != null) {
                m_check.setForeground(header.getForeground());
                m_check.setBackground(header.getBackground());
                m_check.setBorder(new MatteBorder(0, 0, 1, 1, AdempierePLAF.getSecondary1()));
                m_check.setFont(header.getFont());
                m_check.setBorderPainted(true);
                m_check.setEnabled(true);
                header.addMouseListener(this);
            }
        }
        return m_check;
    } else {
        /**
			 * VHeaderRenderer has been created with no argument
			 */
        if (value == null) {
            m_button.setPreferredSize(new Dimension(0, 0));
            return m_button;
        }
        m_button.setText(value.toString());
        m_button.setIcon(icon);
        m_button.setHorizontalTextPosition(SwingConstants.LEADING);
        return m_button;
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) MatteBorder(javax.swing.border.MatteBorder) JLabel(javax.swing.JLabel) JTableHeader(javax.swing.table.JTableHeader) CTable(org.compiere.swing.CTable) Icon(javax.swing.Icon) Dimension(java.awt.Dimension) Component(java.awt.Component)

Aggregations

Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 Icon (javax.swing.Icon)1 JLabel (javax.swing.JLabel)1 MatteBorder (javax.swing.border.MatteBorder)1 JTableHeader (javax.swing.table.JTableHeader)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1 CTable (org.compiere.swing.CTable)1