use of org.knime.core.data.property.ShapeFactory.Shape in project knime-core by knime.
the class ShapeSelectionComboBoxRenderer method setValue.
/**
* {@inheritDoc}
*/
@Override
protected void setValue(final Object value) {
m_combo.setSelectedItem(value);
Shape shape = (Shape) value;
super.setIcon(shape.getIcon());
super.setText(value.toString());
}
use of org.knime.core.data.property.ShapeFactory.Shape in project knime-core by knime.
the class ShapeManagerNodeDialogPane method loadSettingsFrom.
/**
* Updates this dialog by refreshing all components in the shape settings
* tab. Inits the column name combo box and sets the values for the default
* selected one.
*
* @param settings the settings to load
* @param specs the input table specs
* @throws NotConfigurableException if no column contains domain values
* @see NodeDialogPane#loadSettingsFrom(NodeSettingsRO, DataTableSpec[])
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
// remove all columns and column value to shape mappings
m_columns.removeAllItems();
m_map.clear();
// read settings and write into the map
String target = settings.getString(ShapeManagerNodeModel.SELECTED_COLUMN, null);
// add columns and domain value mapping
int cols = specs[0].getNumColumns();
Shape[] shapes = ShapeFactory.getShapes().toArray(new Shape[] {});
for (int i = 0; i < cols; i++) {
DataColumnSpec cspec = specs[0].getColumnSpec(i);
DataColumnDomain domain = cspec.getDomain();
if (domain.hasValues()) {
LinkedHashMap<DataCell, Shape> domMap = new LinkedHashMap<DataCell, Shape>();
int j = 0;
for (DataCell value : domain.getValues()) {
if (value != null) {
String shape = settings.getString(value.toString(), // no settings -> assign different shapes
null);
if (shape == null) {
// bugfix 1283
domMap.put(value, shapes[j++ % shapes.length]);
} else {
domMap.put(value, ShapeFactory.getShape(shape));
}
}
}
m_map.put(cspec.getName(), domMap);
} else {
continue;
}
m_columns.addItem(cspec);
if (cspec.getName().equals(target)) {
m_columns.setSelectedItem(cspec);
}
}
if (m_map.size() == 0) {
throw new NotConfigurableException("No column in data contains" + " domain values.");
}
columnChanged(getSelectedColumn());
m_columns.addItemListener(this);
}
use of org.knime.core.data.property.ShapeFactory.Shape in project knime-core by knime.
the class ShapeManagerNodeDialogPane method columnChanged.
private void columnChanged(final String column) {
final LinkedHashMap<DataCell, Shape> domMap = m_map.get(column);
TableModel tableModel = new DefaultTableModel() {
private final DataCell[] m_valueNames = new DataCell[domMap.size()];
{
int row = 0;
for (DataCell cell : domMap.keySet()) {
m_valueNames[row] = cell;
row++;
}
}
@Override
public String getColumnName(final int columnIdx) {
if (columnIdx == 1) {
return "Shapes";
} else {
return "Values of " + column;
}
}
@Override
public boolean isCellEditable(final int row, final int columnIdx) {
return (columnIdx == 1);
}
@Override
public int getRowCount() {
return domMap.size();
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Class<?> getColumnClass(final int columnIndex) {
if (columnIndex == 1) {
return Shape.class;
} else {
return DataCell.class;
}
}
@Override
public Object getValueAt(final int row, final int columnIndex) {
if (columnIndex == 1) {
return domMap.get(m_valueNames[row]);
} else {
return m_valueNames[row];
}
}
@Override
public void setValueAt(final Object aValue, final int row, final int columnIdx) {
assert aValue instanceof Shape;
assert columnIdx == 1;
domMap.put(m_valueNames[row], (Shape) aValue);
}
};
m_valueTable.setModel(tableModel);
m_valueTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new ShapeSelectionComboBox()));
m_valueTable.getColumnModel().getColumn(1).setCellRenderer(new ShapeSelectionComboBoxRenderer());
}
use of org.knime.core.data.property.ShapeFactory.Shape in project knime-core by knime.
the class ShapeManagerNodeDialogPane method saveSettingsTo.
/**
* Method is invoked by the super class in order to force the dialog to
* apply its changes.
*
* @param settings the object to write the settings into
* @throws InvalidSettingsException if either nominal or range selection
* could not be saved
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
assert (settings != null);
String cell = getSelectedColumn();
settings.addString(ShapeManagerNodeModel.SELECTED_COLUMN, cell);
if (cell != null) {
Map<DataCell, Shape> domMap = m_map.get(cell);
DataCell[] vals = new DataCell[domMap.size()];
int idx = 0;
for (DataCell value : domMap.keySet()) {
vals[idx] = value;
String domValue = vals[idx].toString();
settings.addString(domValue, domMap.get(vals[idx]).toString());
idx++;
}
settings.addDataCellArray(ShapeManagerNodeModel.VALUES, vals);
}
}
use of org.knime.core.data.property.ShapeFactory.Shape in project knime-core by knime.
the class ShapeModelNominal method save.
/**
* Saves the <code>DataCell</code> to <code>Shape</code> mapping to the
* given <code>Config</code>.
* @param config Save settings to.
* @throws NullPointerException If the <i>config</i> is <code>null</code>.
*/
@Override
public void save(final ConfigWO config) {
ConfigWO keyConfig = config.addConfig(CFG_KEYS);
for (Map.Entry<DataCell, Shape> e : m_map.entrySet()) {
DataCell key = e.getKey();
keyConfig.addDataCell(key.toString(), key);
Shape shape = e.getValue();
config.addString(key.toString(), shape.toString());
}
}
Aggregations