use of javax.swing.table.DefaultTableCellRenderer in project vcell by virtualcell.
the class InitialConditionsPanel method initialize.
/**
* Initialize the class.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
// user code begin {1}
// user code end
setName("InitialConditionsPanel");
setLayout(new BorderLayout());
add(getRadioButtonAndCheckboxPanel(), BorderLayout.NORTH);
add(getScrollPaneTable().getEnclosingScrollPane(), BorderLayout.CENTER);
getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
getJMenuItemPaste().addActionListener(ivjEventHandler);
getJMenuItemCopy().addActionListener(ivjEventHandler);
getJMenuItemCopyAll().addActionListener(ivjEventHandler);
getJMenuItemPasteAll().addActionListener(ivjEventHandler);
getAmountRadioButton().addActionListener(ivjEventHandler);
getConcentrationRadioButton().addActionListener(ivjEventHandler);
getRandomizeInitCondnCheckbox().addActionListener(ivjEventHandler);
DefaultTableCellRenderer renderer = new DefaultScrollTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setIcon(null);
defaultToolTipText = null;
if (value instanceof Species) {
setText(((Species) value).getCommonName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof SpeciesContext) {
setText(((SpeciesContext) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof Structure) {
setText(((Structure) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof ScopedExpression) {
SpeciesContextSpec scSpec = tableModel.getValueAt(row);
VCUnitDefinition unit = null;
if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_INITIAL.label)) {
SpeciesContextSpecParameter initialConditionParameter = scSpec.getInitialConditionParameter();
unit = initialConditionParameter.getUnitDefinition();
} else if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_DIFFUSION.label)) {
SpeciesContextSpecParameter diffusionParameter = scSpec.getDiffusionParameter();
unit = diffusionParameter.getUnitDefinition();
}
if (unit != null) {
setHorizontalTextPosition(JLabel.LEFT);
setIcon(new TextIcon("[" + unit.getSymbolUnicode() + "]", DefaultScrollTableCellRenderer.uneditableForeground));
}
int rgb = 0x00ffffff & DefaultScrollTableCellRenderer.uneditableForeground.getRGB();
defaultToolTipText = "<html>" + StringEscapeUtils.escapeHtml4(getText()) + " <font color=#" + Integer.toHexString(rgb) + "> [" + unit.getSymbolUnicode() + "] </font></html>";
setToolTipText(defaultToolTipText);
if (unit != null) {
setText(defaultToolTipText);
}
}
TableModel tableModel = table.getModel();
if (tableModel instanceof SortTableModel) {
DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
setHorizontalTextPosition(JLabel.TRAILING);
}
return this;
}
};
DefaultTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) selectedObject;
SpeciesContext sc = scs.getSpeciesContext();
// sp may be null for "plain" species contexts
SpeciesPattern sp = sc.getSpeciesPattern();
Graphics panelContext = table.getGraphics();
spss = new SpeciesPatternSmallShape(4, 2, sp, shapeManager, panelContext, sc, isSelected, issueManager);
}
} else {
spss = null;
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (spss != null) {
spss.paintSelf(g);
}
}
};
DefaultScrollTableCellRenderer rulesTableCellRenderer = new DefaultScrollTableCellRenderer() {
final Color lightBlueBackground = new Color(214, 234, 248);
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof SpeciesContextSpecsTableModel) {
Icon icon = VCellIcons.issueGoodIcon;
Object selectedObject = null;
if (table.getModel() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (isSelected) {
setBackground(lightBlueBackground);
}
if (selectedObject instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) selectedObject;
SpeciesContext sc = scs.getSpeciesContext();
boolean foundRuleMatch = false;
if (fieldSimulationContext.getRateRules() != null && fieldSimulationContext.getRateRules().length > 0) {
for (RateRule rr : fieldSimulationContext.getRateRules()) {
if (rr.getRateRuleVar() == null) {
continue;
}
if (sc.getName().equals(rr.getRateRuleVar().getName())) {
foundRuleMatch = true;
icon = VCellIcons.ruleRateIcon;
break;
}
}
}
if (!foundRuleMatch && fieldSimulationContext.getAssignmentRules() != null && fieldSimulationContext.getAssignmentRules().length > 0) {
for (AssignmentRule rr : fieldSimulationContext.getAssignmentRules()) {
if (rr.getAssignmentRuleVar() == null) {
continue;
}
if (sc.getName().equals(rr.getAssignmentRuleVar().getName())) {
icon = VCellIcons.ruleAssignIcon;
break;
}
}
}
}
}
setIcon(icon);
}
return this;
}
};
getScrollPaneTable().setDefaultRenderer(SpeciesContext.class, renderer);
getScrollPaneTable().setDefaultRenderer(Structure.class, renderer);
// depiction icons
getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmSpeciesShapeDepictionCellRenderer);
getScrollPaneTable().setDefaultRenderer(Species.class, renderer);
getScrollPaneTable().setDefaultRenderer(ScopedExpression.class, renderer);
getScrollPaneTable().setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
// rules icons
getScrollPaneTable().setDefaultRenderer(SpeciesContextSpecsTableModel.RulesProvenance.class, rulesTableCellRenderer);
// TODO: find out why the code below is not working properly
// int ordinal = SpeciesContextSpecsTableModel.ColumnType.COLUMN_RULES.ordinal();
// getScrollPaneTable().getColumnModel().getColumn(ordinal).setCellRenderer(rulesTableCellRenderer);
// final int rulesWidth = 50; // fixed max size, there's no point to enlarge some columns
// int index = SpeciesContextSpecsTableModel.ColumnType.COLUMN_RULES.ordinal();
// getScrollPaneTable().getColumnModel().getColumn(index).setPreferredWidth(rulesWidth);
// getScrollPaneTable().getColumnModel().getColumn(index).setMaxWidth(rulesWidth);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of javax.swing.table.DefaultTableCellRenderer in project android by JetBrains.
the class IconPickerDialogTest method tableToString.
@NotNull
public static String tableToString(@NotNull JTable table, int startRow, int endRow, int startColumn, int endColumn, int cellWidth) {
StringBuilder sb = new StringBuilder();
String formatString = "%-" + Integer.toString(cellWidth) + "s";
for (int row = Math.max(0, startRow); row < Math.min(endRow, table.getRowCount()); row++) {
for (int column = Math.max(0, startColumn); column < Math.min(table.getColumnCount(), endColumn); column++) {
Object value = table.getValueAt(row, column);
TableCellRenderer renderer = table.getCellRenderer(row, column);
Component component = renderer.getTableCellRendererComponent(table, value, false, false, row, column);
DefaultTableCellRenderer label = (DefaultTableCellRenderer) component;
assertThat(label.getText()).isEmpty();
String cell = label.getAccessibleContext().getAccessibleName();
if (cell.length() > cellWidth) {
cell = cell.substring(0, cellWidth - 3) + "...";
}
sb.append(String.format(formatString, cell));
}
sb.append('\n');
}
return sb.toString();
}
use of javax.swing.table.DefaultTableCellRenderer in project intellij-community by JetBrains.
the class SwingHelper method setNoBorderCellRendererFor.
public static void setNoBorderCellRendererFor(@NotNull TableColumn column) {
final TableCellRenderer previous = column.getCellRenderer();
column.setCellRenderer(new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component;
if (previous != null) {
component = previous.getTableCellRendererComponent(table, value, isSelected, false, row, column);
} else {
component = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
}
if (component instanceof JComponent) {
((JComponent) component).setBorder(null);
}
return component;
}
});
}
use of javax.swing.table.DefaultTableCellRenderer in project intellij-community by JetBrains.
the class ParameterTablePanel method init.
public void init(VariableData[] variableData, Project project, PsiElement... scopeElements) {
super.init(variableData);
myParameterTypeSelectors = new TypeSelector[getVariableData().length];
for (int i = 0; i < myParameterTypeSelectors.length; i++) {
final VariableData data = variableData[i];
final TypeSelector selector = createSelector(project, data, scopeElements);
myParameterTypeSelectors[i] = selector;
//reverse order
getVariableData()[i].type = myParameterTypeSelectors[i].getSelectedType();
}
myTypeRendererCombo = new ComboBox<>(getVariableData());
myTypeRendererCombo.setOpaque(true);
myTypeRendererCombo.setBorder(null);
myTypeRendererCombo.setRenderer(new ListCellRendererWrapper<VariableData>() {
@Override
public void customize(JList list, VariableData value, int index, boolean selected, boolean hasFocus) {
if (value != null) {
setText(value.type.getPresentableText());
}
}
});
final TableColumn typeColumn = myTable.getColumnModel().getColumn(1);
typeColumn.setCellEditor(new AbstractTableCellEditor() {
TypeSelector myCurrentSelector;
final JBComboBoxTableCellEditorComponent myEditorComponent = new JBComboBoxTableCellEditorComponent();
final JLabel myTypeLabel = new JLabel();
@Nullable
public Object getCellEditorValue() {
if (myCurrentSelector.getComponent() instanceof JLabel) {
return myCurrentSelector.getSelectedType();
}
return myEditorComponent.getEditorValue();
}
public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
myCurrentSelector = myParameterTypeSelectors[row];
if (myParameterTypeSelectors[row].getComponent() instanceof JLabel) {
PsiType selectedType = myCurrentSelector.getSelectedType();
if (selectedType != null) {
myTypeLabel.setText(selectedType.getPresentableText());
}
return myTypeLabel;
}
myEditorComponent.setCell(table, row, column);
myEditorComponent.setOptions(myCurrentSelector.getTypes());
myEditorComponent.setDefaultValue(getVariableData()[row].type);
myEditorComponent.setToString(o -> ((PsiType) o).getPresentableText());
return myEditorComponent;
}
});
myTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
private final JBComboBoxLabel myLabel = new JBComboBoxLabel();
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value != null) {
myLabel.setText(((PsiType) value).getPresentableText());
myLabel.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
myLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
if (isSelected) {
myLabel.setSelectionIcon();
} else {
myLabel.setRegularIcon();
}
}
return myLabel;
}
});
}
use of javax.swing.table.DefaultTableCellRenderer in project adempiere by adempiere.
the class MiniTable method autoSize.
/**
* Size Columns.
* Uses Mimimum Column Size
*/
public void autoSize() {
if (!autoResize)
return;
long start = System.currentTimeMillis();
//
// making sure it fits in a column
final int SLACK = 8;
// max size of a column
final int MAXSIZE = 300;
//
TableModel model = this.getModel();
int size = model.getColumnCount();
// for all columns
for (int col = 0; col < size; col++) {
// Column & minimum width
TableColumn tc = this.getColumnModel().getColumn(col);
int width = 0;
if (m_minWidth.size() > col)
width = ((Integer) m_minWidth.get(col)).intValue();
// log.config( "Column=" + col + " " + column.getHeaderValue());
// Header
TableCellRenderer renderer = tc.getHeaderRenderer();
if (renderer == null)
renderer = new DefaultTableCellRenderer();
Component comp = renderer.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, 0);
// log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth());
width = Math.max(width, comp.getPreferredSize().width + SLACK);
// Cells
// first 30 rows
int maxRow = Math.min(30, getRowCount());
for (int row = 0; row < maxRow; row++) {
renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
if (comp != null) {
int rowWidth = comp.getPreferredSize().width + SLACK;
width = Math.max(width, rowWidth);
}
}
// Width not greater ..
width = Math.min(MAXSIZE, width);
tc.setPreferredWidth(width);
// log.fine( "width=" + width);
}
// for all columns
log.finer("Cols=" + size + " - " + (System.currentTimeMillis() - start) + "ms");
}
Aggregations