Search in sources :

Example 1 with DataValueRenderer

use of org.knime.core.data.renderer.DataValueRenderer in project knime-core by knime.

the class TableContentView method fitCellSizeToRenderer.

/**
 * Sets the preferred column width and returns the maximum of the
 * preferred row heights according to each column's renderer.
 * This method should only be called when the table is built up from
 * scratch.
 * @return the best initial row height (this must be set elsewhere)
 */
int fitCellSizeToRenderer() {
    TableColumnModel colModel = getColumnModel();
    int bestRowHeight = 16;
    for (Enumeration<TableColumn> enu = colModel.getColumns(); enu.hasMoreElements(); ) {
        TableColumn col = enu.nextElement();
        TableCellRenderer renderer = col.getCellRenderer();
        if (renderer instanceof DataValueRenderer) {
            if (getRowCount() > 0) {
                prepareRenderer(renderer, 0, col.getModelIndex());
            }
            Dimension p = ((DataValueRenderer) renderer).getPreferredSize();
            int prefHeight = p.height;
            int colWidth = p.width;
            if (col.getWidth() < colWidth) {
                col.setPreferredWidth(colWidth);
            }
            bestRowHeight = Math.max(bestRowHeight, prefHeight);
        }
    }
    return bestRowHeight;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) TableColumnModel(javax.swing.table.TableColumnModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) DataValueRenderer(org.knime.core.data.renderer.DataValueRenderer)

Example 2 with DataValueRenderer

use of org.knime.core.data.renderer.DataValueRenderer in project knime-core by knime.

the class ExtensibleUtilityFactory method getRendererFamily.

/**
 * {@inheritDoc}
 */
@Override
protected final DataValueRendererFamily getRendererFamily(final DataColumnSpec spec) {
    readRenderersFromExtensionPoint();
    DataValueRenderer[] renderers = new DataValueRenderer[m_renderers.size()];
    int i = 0;
    readPreferredRendererFromPreferences();
    DataValueRendererFactory prefRenderer = getPreferredRenderer();
    DataValueRendererFactory defaultRenderer = getDefaultRenderer();
    if (prefRenderer != null) {
        renderers[i++] = prefRenderer.createRenderer(spec);
    } else if (defaultRenderer != null) {
        renderers[i++] = defaultRenderer.createRenderer(spec);
    }
    for (DataValueRendererFactory fac : m_renderers.values()) {
        if (fac.equals(prefRenderer) || ((prefRenderer == null) && fac.equals(defaultRenderer))) {
            continue;
        }
        renderers[i++] = fac.createRenderer(spec);
    }
    return new DefaultDataValueRendererFamily(renderers);
}
Also used : DataValueRendererFactory(org.knime.core.data.renderer.DataValueRendererFactory) DataValueRenderer(org.knime.core.data.renderer.DataValueRenderer) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) DefaultDataValueRendererFamily(org.knime.core.data.renderer.DefaultDataValueRendererFamily)

Aggregations

DataValueRenderer (org.knime.core.data.renderer.DataValueRenderer)2 Dimension (java.awt.Dimension)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1 TableColumn (javax.swing.table.TableColumn)1 TableColumnModel (javax.swing.table.TableColumnModel)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 DataValueRendererFactory (org.knime.core.data.renderer.DataValueRendererFactory)1 DefaultDataValueRendererFamily (org.knime.core.data.renderer.DefaultDataValueRendererFamily)1