Search in sources :

Example 1 with ScrollTableBooleanCellRenderer

use of org.vcell.util.gui.ScrollTable.ScrollTableBooleanCellRenderer 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);
    }
}
Also used : VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) SortTableModel(org.vcell.util.gui.sorttable.SortTableModel) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) BorderLayout(java.awt.BorderLayout) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) RateRule(cbit.vcell.mapping.RateRule) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) TextIcon(cbit.vcell.mapping.gui.StructureMappingTableRenderer.TextIcon) AssignmentRule(cbit.vcell.mapping.AssignmentRule) Color(java.awt.Color) ScrollTableBooleanCellRenderer(org.vcell.util.gui.ScrollTable.ScrollTableBooleanCellRenderer) Graphics(java.awt.Graphics) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ScopedExpression(cbit.gui.ScopedExpression) JTable(javax.swing.JTable) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) Icon(javax.swing.Icon) TextIcon(cbit.vcell.mapping.gui.StructureMappingTableRenderer.TextIcon) TableModel(javax.swing.table.TableModel) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) SortTableModel(org.vcell.util.gui.sorttable.SortTableModel)

Aggregations

ScopedExpression (cbit.gui.ScopedExpression)1 VCellSortTableModel (cbit.vcell.client.desktop.biomodel.VCellSortTableModel)1 SpeciesPatternSmallShape (cbit.vcell.graph.SpeciesPatternSmallShape)1 AssignmentRule (cbit.vcell.mapping.AssignmentRule)1 RateRule (cbit.vcell.mapping.RateRule)1 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)1 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)1 TextIcon (cbit.vcell.mapping.gui.StructureMappingTableRenderer.TextIcon)1 Species (cbit.vcell.model.Species)1 SpeciesContext (cbit.vcell.model.SpeciesContext)1 Structure (cbit.vcell.model.Structure)1 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Graphics (java.awt.Graphics)1 Icon (javax.swing.Icon)1 JTable (javax.swing.JTable)1 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)1 TableModel (javax.swing.table.TableModel)1 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)1