Search in sources :

Example 1 with ColorIconEx

use of org.vcell.util.gui.ColorIconEx 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 2 with ColorIconEx

use of org.vcell.util.gui.ColorIconEx in project vcell by virtualcell.

the class StructureMappingTableModel method updateSubdomainComboBox.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void updateSubdomainComboBox() {
    GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
    DefaultComboBoxModel aModel = new DefaultComboBoxModel();
    for (GeometryClass gc : geometryClasses) {
        aModel.addElement(gc);
    }
    JComboBox subdomainComboBoxCellEditor = new JComboBox();
    subdomainComboBoxCellEditor.setRenderer(new DefaultListCellRenderer() {

        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setHorizontalTextPosition(SwingConstants.LEFT);
            if (value instanceof GeometryClass) {
                GeometryClass gc = (GeometryClass) value;
                setText(gc.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);
                }
            }
            return this;
        }
    });
    subdomainComboBoxCellEditor.setModel(aModel);
    ownerTable.getColumnModel().getColumn(SPATIAL_COLUMN_SUBDOMAIN).setCellEditor(new DefaultCellEditor(subdomainComboBoxCellEditor));
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) ColorIcon(org.vcell.util.gui.ColorIcon) JComboBox(javax.swing.JComboBox) SurfaceClass(cbit.vcell.geometry.SurfaceClass) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DefaultCellEditor(javax.swing.DefaultCellEditor) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) SubVolume(cbit.vcell.geometry.SubVolume) ColorIcon(org.vcell.util.gui.ColorIcon) Icon(javax.swing.Icon) Component(java.awt.Component) ColorIconEx(org.vcell.util.gui.ColorIconEx) JList(javax.swing.JList)

Aggregations

GeometryClass (cbit.vcell.geometry.GeometryClass)2 SubVolume (cbit.vcell.geometry.SubVolume)2 SurfaceClass (cbit.vcell.geometry.SurfaceClass)2 Icon (javax.swing.Icon)2 ColorIcon (org.vcell.util.gui.ColorIcon)2 ColorIconEx (org.vcell.util.gui.ColorIconEx)2 SimulationContext (cbit.vcell.mapping.SimulationContext)1 StructureMapping (cbit.vcell.mapping.StructureMapping)1 BoundaryConditionType (cbit.vcell.math.BoundaryConditionType)1 Structure (cbit.vcell.model.Structure)1 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)1 Color (java.awt.Color)1 Component (java.awt.Component)1 AttributedString (java.text.AttributedString)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 DefaultListCellRenderer (javax.swing.DefaultListCellRenderer)1 JComboBox (javax.swing.JComboBox)1