Search in sources :

Example 6 with MatteBorder

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;
}
Also used : JCheckBox(javax.swing.JCheckBox) MatteBorder(javax.swing.border.MatteBorder) Insets(java.awt.Insets) Color(java.awt.Color) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel) CompoundBorder(javax.swing.border.CompoundBorder) Component(java.awt.Component) JComponent(javax.swing.JComponent) EmptyBorder(javax.swing.border.EmptyBorder)

Example 7 with MatteBorder

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;
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) Issue(org.vcell.util.Issue) MatteBorder(javax.swing.border.MatteBorder) ExpressionPrintFormatter(cbit.vcell.parser.ExpressionPrintFormatter) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) ImageIcon(javax.swing.ImageIcon) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) JLabel(javax.swing.JLabel) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) Dimension(java.awt.Dimension) ScopedExpression(cbit.gui.ScopedExpression) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) TableModel(javax.swing.table.TableModel)

Example 8 with MatteBorder

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;
}
Also used : Color(java.awt.Color) GeometryClass(cbit.vcell.geometry.GeometryClass) Set(java.util.Set) Issue(org.vcell.util.Issue) SurfaceClass(cbit.vcell.geometry.SurfaceClass) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) AttributedString(java.text.AttributedString) StructureMapping(cbit.vcell.mapping.StructureMapping) MatteBorder(javax.swing.border.MatteBorder) SubVolume(cbit.vcell.geometry.SubVolume) Iterator(java.util.Iterator) Structure(cbit.vcell.model.Structure) ColorIconEx(org.vcell.util.gui.ColorIconEx) ColorIcon(org.vcell.util.gui.ColorIcon) Color(java.awt.Color) SimulationContext(cbit.vcell.mapping.SimulationContext) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ColorIcon(org.vcell.util.gui.ColorIcon) Icon(javax.swing.Icon)

Example 9 with MatteBorder

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;
}
Also used : MatteBorder(javax.swing.border.MatteBorder) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with MatteBorder

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;
}
Also used : MatteBorder(javax.swing.border.MatteBorder) ActionListener(java.awt.event.ActionListener) ComboBox(com.intellij.openapi.ui.ComboBox) ActionEvent(java.awt.event.ActionEvent)

Aggregations

MatteBorder (javax.swing.border.MatteBorder)12 Color (java.awt.Color)5 Dimension (java.awt.Dimension)5 Insets (java.awt.Insets)4 Icon (javax.swing.Icon)3 JLabel (javax.swing.JLabel)3 EmptyBorder (javax.swing.border.EmptyBorder)3 Issue (org.vcell.util.Issue)3 Component (java.awt.Component)2 ImageIcon (javax.swing.ImageIcon)2 CompoundBorder (javax.swing.border.CompoundBorder)2 ScopedExpression (cbit.gui.ScopedExpression)1 SpatialObjectTableModel (cbit.vcell.client.desktop.biomodel.SpatialObjectTableModel)1 SpatialProcessTableModel (cbit.vcell.client.desktop.biomodel.SpatialProcessTableModel)1 VCellSortTableModel (cbit.vcell.client.desktop.biomodel.VCellSortTableModel)1 GeometryClass (cbit.vcell.geometry.GeometryClass)1 SubVolume (cbit.vcell.geometry.SubVolume)1 SurfaceClass (cbit.vcell.geometry.SurfaceClass)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)1