use of javax.swing.border.MatteBorder in project adempiere by adempiere.
the class MiniTable method prepareRenderer.
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component c = super.prepareRenderer(renderer, row, column);
JComponent jc = (JComponent) c;
if (c == null)
return c;
// Row is selected
Color selectedColor = AdempierePLAF.getFieldBackground_Selected();
// Even row
Color normalColor = AdempierePLAF.getFieldBackground_Normal();
// Odd row
Color backColor = AdempierePLAF.getInfoBackground();
// Lead row border
Color borderColor = AdempierePLAF.getFieldBackground_Mandatory();
CompoundBorder cb = null;
ListSelectionModel rsm = this.getSelectionModel();
boolean readOnly = !this.isCellEditable(row, column);
if (!(row == rsm.getLeadSelectionIndex())) {
if (// Highlighted but not the lead
rsm.isSelectedIndex(row)) {
c.setBackground(selectedColor);
jc.setBorder(new MatteBorder(1, 1, 1, 1, selectedColor));
} else if (// Not selected but even in number
row % 2 == 0) {
c.setBackground(normalColor);
jc.setBorder(new MatteBorder(1, 1, 1, 1, normalColor));
} else // Not selected and odd in number
{
// If not shaded, match the table's background
c.setBackground(backColor);
jc.setBorder(new MatteBorder(1, 1, 1, 1, backColor));
}
// Buttons and checkboxes need to have the border turned on
if (c.getClass().equals(JCheckBox.class)) {
((JCheckBox) c).setBorderPainted(false);
} else if (c.getClass().equals(JButton.class)) {
((JButton) c).setBorderPainted(false);
}
} else {
if (c.getClass().equals(JCheckBox.class)) {
((JCheckBox) c).setBorderPainted(true);
} else if (c.getClass().equals(JButton.class)) {
((JButton) c).setBorderPainted(true);
}
// Define border - compond border maintains the spacing of 1px around the field
if (column == 0) {
cb = new CompoundBorder(new EmptyBorder(new Insets(0, 0, 0, 1)), new MatteBorder(1, 1, 1, 0, borderColor));
} else if (column == this.getColumnCount() - 1) {
cb = new CompoundBorder(new EmptyBorder(new Insets(0, 1, 0, 0)), new MatteBorder(1, 0, 1, 1, borderColor));
} else {
cb = new CompoundBorder(new EmptyBorder(new Insets(0, 1, 0, 1)), new MatteBorder(1, 0, 1, 0, borderColor));
}
// Set border
jc.setBorder(cb);
// Set background color
if (!readOnly && this.isRowChecked(row))
c.setBackground(normalColor);
else
c.setBackground(selectedColor);
}
return c;
}
use of javax.swing.border.MatteBorder in project vcell by virtualcell.
the class ScopedExpressionTableCellRenderer method getTableCellRendererComponent.
/**
* This method is sent to the renderer by the drawing table to
* configure the renderer appropriately before drawing. Return
* the Component used for drawing.
*
* @param table the JTable that is asking the renderer to draw.
* This parameter can be null.
* @param value the value of the cell to be rendered. It is
* up to the specific renderer to interpret
* and draw the value. eg. if value is the
* String "true", it could be rendered as a
* string or it could be rendered as a check
* box that is checked. null is a valid value.
* @param isSelected true is the cell is to be renderer with
* selection highlighting
* @param row the row index of the cell being drawn. When
* drawing the header the rowIndex is -1.
* @param column the column index of the cell being drawn
*/
public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
try {
TableModel tableModel = table.getModel();
if (value == null) {
templateJLabel.setIcon(null);
templateJLabel.setText(null);
templateJLabel.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (tableModel instanceof VCellSortTableModel) {
if (row < ((VCellSortTableModel<?>) tableModel).getRowCount()) {
Object rowObject = ((VCellSortTableModel<?>) tableModel).getValueAt(row);
if (rowObject instanceof SpeciesContextSpecParameter) {
templateJLabel.setText(((SpeciesContextSpecParameter) rowObject).getNullExpressionDescription());
}
}
}
return templateJLabel;
}
if (!(value instanceof ScopedExpression)) {
return stringRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
imageRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
JLabel renderer = imageRenderer;
ScopedExpression scopedExpression = (ScopedExpression) value;
String scopedExpressInfix = scopedExpression.infix();
ReusableExpressionIcon rei = scopedExpressionImageIconHash.get(scopedExpressInfix);
if (rei != null && rei.background.equals(imageRenderer.getBackground()) && rei.foreground.equals(imageRenderer.getForeground())) {
// Re-use existing ImageIcon is it exists and is same state
imageRenderer.setIcon(rei.imageIcon);
} else {
// Create new ImageIcon
try {
ExpressionPrintFormatter epf = new ExpressionPrintFormatter(scopedExpression.getRenamedExpression());
//
// Use graphicsContextProvider BufferedImage to get started because
// theTable may have a null GC and epf needs a non-null GC
//
java.awt.Graphics2D tempG2D = (java.awt.Graphics2D) graphicsContextProvider.getGraphics();
// Must set here before epf.getSize is called
tempG2D.setFont(italicFont);
// Determine how big the expression image will be
java.awt.Dimension dim = epf.getSize(tempG2D);
// Create and render the expression image
java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage(dim.width, dim.height, java.awt.image.BufferedImage.TYPE_INT_RGB);
java.awt.Graphics2D g2d = bi.createGraphics();
// epf.paint needs a non-null clipBounds
g2d.setClip(0, 0, dim.width, dim.height);
// set the SAME font used in epf.getSize
g2d.setFont(italicFont);
if (table != null && imageRenderer != null) {
g2d.setBackground(imageRenderer.getBackground());
g2d.setColor(imageRenderer.getForeground());
}
// paint background
g2d.clearRect(0, 0, dim.width, dim.height);
// paint expression into image
epf.paint(g2d);
// Limit cacheing in case a large number of DIFFERENT expressions are being serviced by this TableCellRenderer.
if ((scopedExpressionCacheSize + (dim.width * dim.height)) >= CACHE_SIZE_LIMIT) {
scopedExpressionImageIconHash.clear();
scopedExpressionCacheSize = 0;
}
javax.swing.ImageIcon newImageIcon = new javax.swing.ImageIcon(bi);
rei = new ReusableExpressionIcon(newImageIcon, imageRenderer.getBackground(), imageRenderer.getForeground());
if (scopedExpressionImageIconHash.put(scopedExpressInfix, rei) == null) {
scopedExpressionCacheSize += dim.width * dim.height;
}
imageRenderer.setIcon(newImageIcon);
} catch (Exception e) {
// Fallback to String
e.printStackTrace();
templateJLabel.setText(scopedExpression.infix());
renderer = templateJLabel;
}
}
ExpressionBindingException expressionBindingException = scopedExpression.getExpressionBindingException();
if (expressionBindingException != null) {
renderer.setBorder(BorderFactory.createLineBorder(Color.red));
renderer.setToolTipText(expressionBindingException.getMessage());
} else {
renderer.setBorder(BorderFactory.createEmptyBorder());
renderer.setToolTipText(null);
}
if (tableModel instanceof VCellSortTableModel) {
List<Issue> issueList = ((VCellSortTableModel<?>) tableModel).getIssues(row, column, Issue.SEVERITY_ERROR);
if (issueList.size() > 0) {
renderer.setToolTipText(Issue.getHtmlIssueMessage(issueList));
if (column == 0) {
renderer.setBorder(new MatteBorder(1, 1, 1, 0, Color.red));
} else if (column == table.getColumnCount() - 1) {
renderer.setBorder(new MatteBorder(1, 0, 1, 1, Color.red));
} else {
renderer.setBorder(new MatteBorder(1, 0, 1, 0, Color.red));
}
} else {
renderer.setBorder(BORDER);
}
}
return renderer;
} catch (Exception e) {
e.printStackTrace();
templateJLabel.setText("ScopedExpressionTableCellRenderer Error - " + e.getMessage() + " " + value);
return templateJLabel;
}
}
use of javax.swing.border.MatteBorder in project vcell by virtualcell.
the class StructureMappingTableRenderer method getTableCellRendererComponent.
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);
if (table.getModel() instanceof StructureMappingTableModel) {
StructureMappingTableModel structureMappingTableModel = (StructureMappingTableModel) table.getModel();
String toolTip = structureMappingTableModel.getToolTip(row, column);
if (value instanceof Structure) {
Structure structure = (Structure) value;
setText(structure.getName());
} else if (value instanceof Double && structureMappingTableModel.isNewSizeColumn(column)) {
StructureMapping structureMapping = structureMappingTableModel.getStructureMapping(row);
if (structureMappingTableModel.isNonSpatial()) {
VCUnitDefinition unitDefinition = structureMapping.getStructure().getStructureSize().getUnitDefinition();
TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
if (sizeIcon == null) {
sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
}
setIcon(sizeIcon);
} else {
// spatial
if (structureMapping.getUnitSizeParameter() != null) {
VCUnitDefinition unitDefinition = structureMapping.getUnitSizeParameter().getUnitDefinition();
TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
if (sizeIcon == null) {
sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
}
setIcon(sizeIcon);
}
}
}
if (structureMappingTableModel.isSubdomainColumn(column)) {
// can be null
if (value == null) {
setText("Unmapped");
setForeground(Color.red);
setIcon(null);
} else {
if (value instanceof GeometryClass) {
setText(((GeometryClass) value).getName());
if (value instanceof SubVolume) {
SubVolume subVolume = (SubVolume) value;
java.awt.Color handleColor = new java.awt.Color(colormap[subVolume.getHandle()]);
// small square icon with subdomain color
Icon icon = new ColorIcon(10, 10, handleColor, true);
setHorizontalTextPosition(SwingConstants.RIGHT);
setIcon(icon);
} else if (value instanceof SurfaceClass) {
SurfaceClass sc = (SurfaceClass) value;
Set<SubVolume> sv = sc.getAdjacentSubvolumes();
Iterator<SubVolume> iterator = sv.iterator();
SubVolume sv1 = iterator.next();
SubVolume sv2 = iterator.next();
java.awt.Color c1 = new java.awt.Color(colormap[sv2.getHandle()]);
java.awt.Color c2 = new java.awt.Color(colormap[sv1.getHandle()]);
Icon icon = new ColorIconEx(10, 10, c1, c2);
setIcon(icon);
setHorizontalTextPosition(SwingConstants.RIGHT);
}
} else {
setText(value.toString());
setIcon(null);
}
}
}
if (value instanceof BoundaryConditionType) {
// we get here only for spatial
Object candidate = structureMappingTableModel.getValueAt(row, StructureMappingTableModel.SPATIAL_COLUMN_SUBDOMAIN);
if (candidate instanceof SurfaceClass) {
SurfaceClass surfaceClass = (SurfaceClass) candidate;
cbit.vcell.model.Model model = structureMappingTableModel.getGeometryContext().getModel();
SimulationContext simContext = structureMappingTableModel.getGeometryContext().getSimulationContext();
Pair<SubVolume, SubVolume> ret = DiffEquMathMapping.computeBoundaryConditionSource(model, simContext, surfaceClass);
SubVolume innerSubVolume = ret.one;
java.awt.Color handleColor = new java.awt.Color(colormap[innerSubVolume.getHandle()]);
// small square icon with subdomain color
Icon icon = new ColorIcon(8, 8, handleColor, true);
setHorizontalTextPosition(SwingConstants.LEFT);
setIcon(icon);
setText("from");
// override default tooltip
toolTip = "Boundary condition inherited from Subdomain '" + innerSubVolume.getName() + "'";
setToolTipText(toolTip);
} else {
setText(((BoundaryConditionType) value).boundaryTypeStringValue());
}
}
List<Issue> issueList = structureMappingTableModel.getIssues(row, column, Issue.SEVERITY_ERROR);
if (issueList.size() > 0) {
// override default tooltip
setToolTipText(Issue.getHtmlIssueMessage(issueList));
if (column == 0) {
setBorder(new MatteBorder(1, 1, 1, 0, Color.red));
} else if (column == table.getColumnCount() - 1) {
setBorder(new MatteBorder(1, 0, 1, 1, Color.red));
} else {
setBorder(new MatteBorder(1, 0, 1, 0, Color.red));
}
} else {
setToolTipText(toolTip);
setBorder(DEFAULT_GAP);
}
}
return this;
}
use of javax.swing.border.MatteBorder in project intellij-plugins by JetBrains.
the class BaseSortableTreeTable method prepareRenderer.
@NotNull
@Override
public Component prepareRenderer(@NotNull TableCellRenderer renderer, int row, int column) {
JComponent jComponent = (JComponent) super.prepareRenderer(renderer, row, column);
jComponent.setBorder(new MatteBorder(0, 0, 1, 0, JBColor.LIGHT_GRAY));
return jComponent;
}
use of javax.swing.border.MatteBorder in project intellij-community by JetBrains.
the class IpnbFileEditor method createControlPanel.
private JPanel createControlPanel() {
final JPanel controlPanel = new JPanel();
controlPanel.setBackground(IpnbEditorUtil.getBackground());
final JPanel savePanel = new JPanel(new GridBagLayout());
savePanel.setBackground(IpnbEditorUtil.getBackground());
addSaveButton(savePanel);
controlPanel.add(savePanel);
final JPanel addPanel = new JPanel(new GridBagLayout());
addPanel.setBackground(IpnbEditorUtil.getBackground());
addAddButton(addPanel);
controlPanel.add(addPanel);
final JPanel editorPanel = new JPanel(new GridBagLayout());
editorPanel.setBackground(IpnbEditorUtil.getBackground());
addCutButton(editorPanel);
addCopyButton(editorPanel);
addPasteButton(editorPanel);
controlPanel.add(editorPanel);
final JPanel runPanel = new JPanel(new GridBagLayout());
runPanel.setBackground(IpnbEditorUtil.getBackground());
addRunButton(runPanel);
controlPanel.add(runPanel);
addInterruptKernelButton(runPanel);
addReloadKernelButton(runPanel);
myCellTypeCombo = new ComboBox(ourCellTypes);
myCellTypeCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final Object selectedItem = myCellTypeCombo.getSelectedItem();
final IpnbEditablePanel selectedCellPanel = myIpnbFilePanel.getSelectedCellPanel();
if (selectedCellPanel != null && selectedItem instanceof String) {
updateCellType((String) selectedItem, selectedCellPanel);
}
}
});
final IpnbPanel selectedCellPanel = myIpnbFilePanel.getSelectedCellPanel();
if (selectedCellPanel != null) {
updateCellTypeCombo(selectedCellPanel);
}
controlPanel.add(myCellTypeCombo);
final MatteBorder border = BorderFactory.createMatteBorder(0, 0, 1, 0, JBColor.GRAY);
controlPanel.setBorder(border);
return controlPanel;
}
Aggregations