Search in sources :

Example 91 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project vcell by virtualcell.

the class RateRulesSummaryTableModel method updateSubdomainComboBox.

private void updateSubdomainComboBox() {
    if (steComboBox == null) {
        steComboBox = new JComboBox<>();
    }
    if (simulationContext == null) {
        return;
    }
    SpeciesContext[] scs = simulationContext.getModel().getSpeciesContexts();
    ModelParameter[] mps = simulationContext.getModel().getModelParameters();
    DefaultComboBoxModel<String> aModel = new DefaultComboBoxModel<>();
    for (SpeciesContext sc : scs) {
        aModel.addElement(sc.getName());
    }
    for (ModelParameter mp : mps) {
        aModel.addElement(mp.getName());
    }
    steComboBox.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
        }

        @Override
        public void mouseEntered(java.awt.event.MouseEvent evt) {
        }
    });
    steComboBox.addFocusListener(new java.awt.event.FocusAdapter() {

        @Override
        public void focusGained(java.awt.event.FocusEvent evt) {
            DefaultComboBoxModel<String> aModel = (DefaultComboBoxModel<String>) steComboBox.getModel();
            SpeciesContext[] scs = simulationContext.getModel().getSpeciesContexts();
            ModelParameter[] mps = simulationContext.getModel().getModelParameters();
            for (SpeciesContext sc : scs) {
                int position = aModel.getIndexOf(sc.getName());
                if (position == -1) {
                    // element is missing, add it
                    aModel.addElement(sc.getName());
                }
            }
            for (ModelParameter mp : mps) {
                int position = aModel.getIndexOf(mp.getName());
                if (position == -1) {
                    aModel.addElement(mp.getName());
                }
            }
            Set<String> elementsToRemove = new HashSet<>();
            for (int i = 0; i < aModel.getSize(); i++) {
                String candidate = aModel.getElementAt(i);
                SpeciesContext sc = simulationContext.getModel().getSpeciesContext(candidate);
                ModelParameter mp = simulationContext.getModel().getModelParameter(candidate);
                if (sc == null && mp == null) {
                    elementsToRemove.add(candidate);
                }
                if (sc != null && simulationContext.getAssignmentRule(sc) != null) {
                    elementsToRemove.add(candidate);
                    continue;
                }
                if (mp != null && simulationContext.getAssignmentRule(mp) != null) {
                    elementsToRemove.add(candidate);
                    continue;
                }
            }
            for (String candidate : elementsToRemove) {
                aModel.removeElement(candidate);
            }
        }
    });
    steComboBox.setRenderer(new DefaultListCellRenderer() {

        @Override
        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 == null) {
                setText("");
            } else if (value instanceof String) {
                setText((String) value);
            } else {
                setText(value.toString());
                System.out.println("not String");
            }
            return this;
        }
    });
    steComboBox.setModel(aModel);
    ownerTable.getColumnModel().getColumn(COLUMN_RATERULE_VAR).setCellEditor(new DefaultCellEditor(steComboBox));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SpeciesContext(cbit.vcell.model.SpeciesContext) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DefaultCellEditor(javax.swing.DefaultCellEditor) ModelParameter(cbit.vcell.model.Model.ModelParameter) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Component(java.awt.Component)

Example 92 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project vcell by virtualcell.

the class OutputFunctionsListTableModel method setAvailableDomains.

public void setAvailableDomains(GeometryClass[] availableGeometryClasses) {
    this.availableGeometryClasses = availableGeometryClasses;
    if (ownerTable.getColumnModel().getColumnCount() > COLUMN_OUTPUTFN_VARIABLETYPE) {
        TableColumn varTypeCol = ownerTable.getColumnModel().getColumn(COLUMN_OUTPUTFN_VARIABLETYPE);
        JComboBox<String> varTypesCB = new JComboBox<>();
        for (int i = 0; availableGeometryClasses != null && i < availableGeometryClasses.length; i++) {
            varTypesCB.addItem(availableGeometryClasses[i].getName());
        }
        varTypeCol.setCellEditor(new DefaultCellEditor(varTypesCB));
    }
}
Also used : JComboBox(javax.swing.JComboBox) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 93 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project vcell by virtualcell.

the class SimulationListPanel method initConnections.

/**
 * Initializes connections
 * @exception java.lang.Exception The exception description.
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() throws java.lang.Exception {
    // user code begin {1}
    // user code end
    getNewButton().addActionListener(ivjEventHandler);
    getEditButton().addActionListener(ivjEventHandler);
    getDeleteButton().addActionListener(ivjEventHandler);
    getRunButton().addActionListener(ivjEventHandler);
    getMassConservationModelReductionCheckBox().addActionListener(ivjEventHandler);
    getMassConservationModelReductionHelpButton().addActionListener(ivjEventHandler);
    // getPythonResultsButton().addActionListener(ivjEventHandler);
    getNativeResultsButton().addActionListener(ivjEventHandler);
    getMoreActionsButton().addActionListener(ivjEventHandler);
    getScrollPaneTable().addPropertyChangeListener(ivjEventHandler);
    getOutputFunctionsPanel().addPropertyChangeListener(ivjEventHandler);
    getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
    DefaultScrollTableCellRenderer renderer = new DefaultScrollTableCellRenderer() {

        @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 (value instanceof OutputTimeSpec) {
                SimulationWorkspace sw = getSimulationWorkspace();
                SimulationOwner so = sw.getSimulationOwner();
                UnitInfo unitInfo = so.getUnitInfo();
                Objects.requireNonNull(unitInfo);
                OutputTimeSpec ots = (OutputTimeSpec) value;
                String text = ots.describe(unitInfo);
                setText(text);
            } else if (value instanceof Double) {
                setText(value + "");
            }
            boolean bFinitVolumeRerun = false;
            if (value instanceof SolverDescription) {
                SolverDescription solverDescription = (SolverDescription) value;
                try {
                    if (FINITEVOLUME_CUTTOFF != null && solverDescription.equals(SolverDescription.FiniteVolume)) /*Compiled Solver*/
                    {
                        SimulationStatus simStatus = getSimulationWorkspace().getSimulationStatus(getSimulationListTableModel1().getValueAt(row));
                        if (simStatus.getHasData()) {
                            int statusIndex = 0;
                            while (simStatus.getJobStatus(statusIndex) != null) {
                                if (simStatus.getJobStatus(statusIndex).getEndDate().compareTo(FINITEVOLUME_CUTTOFF) > 0) {
                                    bFinitVolumeRerun = true;
                                    break;
                                }
                                statusIndex++;
                            }
                        }
                    }
                } catch (Exception e) {
                    // ignore, let table cell render anyway
                    e.printStackTrace();
                }
                setText(solverDescription.getShortDisplayLabel());
                setToolTipText(solverDescription.getDisplayLabel());
            } else {
                setToolTipText(getText());
            }
            if (bFinitVolumeRerun) {
                setText(getText() + (bFinitVolumeRerun ? "(*)" : ""));
                setToolTipText(getToolTipText() + (bFinitVolumeRerun ? " (data regenerated using FiniteVolumeStandalone)" : ""));
            }
            return this;
        }
    };
    getScrollPaneTable().setDefaultRenderer(OutputTimeSpec.class, renderer);
    getScrollPaneTable().setDefaultRenderer(Double.class, renderer);
    getScrollPaneTable().setDefaultRenderer(String.class, renderer);
    getScrollPaneTable().setDefaultRenderer(SolverDescription.class, renderer);
    getScrollPaneTable().setDefaultEditor(OutputTimeSpec.class, new DefaultCellEditor(new JTextField()));
    getScrollPaneTable().setDefaultRenderer(SimulationStatus.class, new DefaultScrollTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Object obj = getSimulationStatusDisplay(row);
            if (obj instanceof JProgressBar) {
                return (JProgressBar) obj;
            }
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (value instanceof SimulationStatus) {
                setText(obj.toString());
                String details = ((SimulationStatus) value).getDetails();
                setToolTipText(details);
            }
            return this;
        }
    });
}
Also used : SolverDescription(cbit.vcell.solver.SolverDescription) JProgressBar(javax.swing.JProgressBar) JTextField(javax.swing.JTextField) PropertyVetoException(java.beans.PropertyVetoException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) DefaultCellEditor(javax.swing.DefaultCellEditor) SimulationOwner(cbit.vcell.solver.SimulationOwner) UnitInfo(cbit.vcell.solver.SimulationOwner.UnitInfo) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) SimulationStatus(cbit.vcell.server.SimulationStatus) JTable(javax.swing.JTable) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) Component(java.awt.Component)

Example 94 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project zaproxy by zaproxy.

the class PolicyPassiveScanPanel method getTableTest.

/**
     * This method initializes tableTest
     *
     * @return javax.swing.JTable
     */
private JTable getTableTest() {
    if (tableTest == null) {
        tableTest = new JTable();
        tableTest.setModel(getPassiveScanTableModel());
        tableTest.setRowHeight(DisplayUtils.getScaledSize(18));
        tableTest.setIntercellSpacing(new java.awt.Dimension(1, 1));
        tableTest.setAutoCreateRowSorter(true);
        //Default sort by name (column 0)
        List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(1);
        sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
        tableTest.getRowSorter().setSortKeys(sortKeys);
        for (int i = 0; i < tableTest.getColumnCount() - 1; i++) {
            TableColumn column = tableTest.getColumnModel().getColumn(i);
            column.setPreferredWidth(width[i]);
        }
        JComboBox<String> jcb1 = new JComboBox<>();
        for (AlertThreshold level : AlertThreshold.values()) {
            jcb1.addItem(Constant.messages.getString("ascan.policy.level." + level.name().toLowerCase()));
        }
        tableTest.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(jcb1));
    }
    return tableTest;
}
Also used : RowSorter(javax.swing.RowSorter) JComboBox(javax.swing.JComboBox) ArrayList(java.util.ArrayList) TableColumn(javax.swing.table.TableColumn) AlertThreshold(org.parosproxy.paros.core.scanner.Plugin.AlertThreshold) DefaultCellEditor(javax.swing.DefaultCellEditor) JTable(javax.swing.JTable)

Example 95 with DefaultCellEditor

use of javax.swing.DefaultCellEditor in project ACS by ACS-Community.

the class CDBTable method setUpStringEditor.

public void setUpStringEditor() {
    // , this);
    final StringField stringField = new StringField("", 3);
    DefaultCellEditor stringEditor = new DefaultCellEditor(stringField) {

        public Object getCellEditorValue() {
            return stringField.getValue();
        }
    };
    setDefaultEditor(String.class, stringEditor);
}
Also used : DefaultCellEditor(javax.swing.DefaultCellEditor)

Aggregations

DefaultCellEditor (javax.swing.DefaultCellEditor)191 JComboBox (javax.swing.JComboBox)119 JTable (javax.swing.JTable)61 TableColumn (javax.swing.table.TableColumn)61 ArrayList (java.util.ArrayList)47 TableCellEditor (javax.swing.table.TableCellEditor)35 JScrollPane (javax.swing.JScrollPane)33 JPanel (javax.swing.JPanel)26 ActionEvent (java.awt.event.ActionEvent)25 JTextField (javax.swing.JTextField)23 ProxyColumn (us.mn.state.dot.tms.client.proxy.ProxyColumn)23 JLabel (javax.swing.JLabel)22 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)22 Component (java.awt.Component)21 DefaultTableModel (javax.swing.table.DefaultTableModel)21 Dimension (java.awt.Dimension)17 ActionListener (java.awt.event.ActionListener)16 JButton (javax.swing.JButton)16 JCheckBox (javax.swing.JCheckBox)16 TableCellRenderer (javax.swing.table.TableCellRenderer)15