Search in sources :

Example 6 with DefaultListSelectionModel

use of javax.swing.DefaultListSelectionModel in project jdk8u_jdk by JetBrains.

the class PathPlaceHolder method insureRowContinuity.

/**
     * Makes sure the currently selected <code>TreePath</code>s are valid
     * for the current selection mode.
     * If the selection mode is <code>CONTIGUOUS_TREE_SELECTION</code>
     * and a <code>RowMapper</code> exists, this will make sure all
     * the rows are contiguous, that is, when sorted all the rows are
     * in order with no gaps.
     * If the selection isn't contiguous, the selection is
     * reset to contain the first set, when sorted, of contiguous rows.
     * <p>
     * If the selection mode is <code>SINGLE_TREE_SELECTION</code> and
     * more than one TreePath is selected, the selection is reset to
     * contain the first path currently selected.
     */
protected void insureRowContinuity() {
    if (selectionMode == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION && selection != null && rowMapper != null) {
        DefaultListSelectionModel lModel = listSelectionModel;
        int min = lModel.getMinSelectionIndex();
        if (min != -1) {
            for (int counter = min, maxCounter = lModel.getMaxSelectionIndex(); counter <= maxCounter; counter++) {
                if (!lModel.isSelectedIndex(counter)) {
                    if (counter == min) {
                        clearSelection();
                    } else {
                        TreePath[] newSel = new TreePath[counter - min];
                        int[] selectionIndex = rowMapper.getRowsForPaths(selection);
                        // rows of the new selection
                        for (int i = 0; i < selectionIndex.length; i++) {
                            if (selectionIndex[i] < counter) {
                                newSel[selectionIndex[i] - min] = selection[i];
                            }
                        }
                        setSelectionPaths(newSel);
                        break;
                    }
                }
            }
        }
    } else if (selectionMode == TreeSelectionModel.SINGLE_TREE_SELECTION && selection != null && selection.length > 1) {
        setSelectionPath(selection[0]);
    }
}
Also used : DefaultListSelectionModel(javax.swing.DefaultListSelectionModel)

Example 7 with DefaultListSelectionModel

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

the class SimResultsViewer method initialize.

/**
 * Insert the method's description here.
 * Creation date: (10/17/2005 11:37:52 PM)
 * @exception org.vcell.util.DataAccessException The exception description.
 */
private void initialize() throws DataAccessException {
    // create main viewer for jobIndex 0 and wire it up
    if (isODEData) {
        setMainViewer(createODEDataViewer());
    } else {
        setMainViewer(createPDEDataViewer());
    }
    java.beans.PropertyChangeListener pcl = new java.beans.PropertyChangeListener() {

        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            if (evt.getSource() == SimResultsViewer.this && (evt.getPropertyName().equals("dataViewerManager"))) {
                try {
                    getMainViewer().setDataViewerManager(getDataViewerManager());
                } catch (java.beans.PropertyVetoException exc) {
                    exc.printStackTrace();
                }
            }
            if (evt.getSource() == SimResultsViewer.this && (evt.getPropertyName().equals("simulationModelInfo"))) {
                getMainViewer().setSimulationModelInfo(getSimulationModelInfo());
            }
        }
    };
    addPropertyChangeListener(pcl);
    // if necessarry, create parameter choices panel and wire it up
    if (getSimulation().getScanCount() > 1) {
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout(5, 0));
        panel.setBorder(BorderFactory.createEtchedBorder());
        JLabel label = new JLabel("<html><b>Choose Parameter Values</b></html>");
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setBorder(BorderFactory.createEmptyBorder(2, 2, 0, 2));
        panel.add(label, BorderLayout.NORTH);
        String[] scanParams = getSimulation().getMathOverrides().getScannedConstantNames();
        Arrays.sort(scanParams);
        JPanel tablePanel = new JPanel();
        tablePanel.setLayout(new BoxLayout(tablePanel, BoxLayout.X_AXIS));
        for (int i = 0; i < scanParams.length; i++) {
            Constant[] scanConstants = getSimulation().getMathOverrides().getConstantArraySpec(scanParams[i]).getConstants();
            String[][] values = new String[scanConstants.length][1];
            for (int j = 0; j < scanConstants.length; j++) {
                values[j][0] = scanConstants[j].getExpression().infix();
            }
            class ScanChoicesTableModel extends javax.swing.table.AbstractTableModel {

                String[] columnNames;

                Object[][] rowData;

                ScanChoicesTableModel(Object[][] argData, String[] argNames) {
                    columnNames = argNames;
                    rowData = argData;
                }

                public String getColumnName(int column) {
                    return columnNames[column].toString();
                }

                public int getRowCount() {
                    return rowData.length;
                }

                public int getColumnCount() {
                    return columnNames.length;
                }

                public Object getValueAt(int row, int col) {
                    return rowData[row][col];
                }

                public boolean isCellEditable(int row, int column) {
                    return false;
                }

                public void setValueAt(Object value, int row, int col) {
                    rowData[row][col] = value;
                    fireTableCellUpdated(row, col);
                }
            }
            ;
            ScanChoicesTableModel tm = new ScanChoicesTableModel(values, new String[] { scanParams[i] });
            final JTable table = new JTable(tm);
            choicesHash.put(scanParams[i], table);
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            table.getSelectionModel().setSelectionInterval(0, 0);
            final ListSelectionListener[] nextListSelectionListener = new ListSelectionListener[1];
            nextListSelectionListener[0] = new javax.swing.event.ListSelectionListener() {

                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                    if (!e.getValueIsAdjusting()) {
                        DefaultListSelectionModel list = (DefaultListSelectionModel) e.getSource();
                        int selected = list.getAnchorSelectionIndex();
                        final int previous = (selected == e.getFirstIndex() ? e.getLastIndex() : e.getFirstIndex());
                        ListReset listReset = new ListReset() {

                            @Override
                            public void reset(VCDataIdentifier myVcDataIdentifier) {
                                if (myVcDataIdentifier instanceof VCSimulationDataIdentifier) {
                                    int paramScanIndex = ((VCSimulationDataIdentifier) myVcDataIdentifier).getJobIndex();
                                    table.getSelectionModel().removeListSelectionListener(nextListSelectionListener[0]);
                                    try {
                                        table.setRowSelectionInterval(paramScanIndex, paramScanIndex);
                                    } finally {
                                        table.getSelectionModel().addListSelectionListener(nextListSelectionListener[0]);
                                    }
                                } else {
                                    table.setRowSelectionInterval(previous, previous);
                                }
                            }
                        };
                        updateScanParamChoices("SimResultsViewer set paramScan index=" + getSelectedParamScanJobIndex(), listReset);
                    }
                }
            };
            table.getSelectionModel().addListSelectionListener(nextListSelectionListener[0]);
            JScrollPane scr = new JScrollPane(table);
            JPanel p = new JPanel();
            scr.setPreferredSize(new java.awt.Dimension(100, Math.min(150, table.getPreferredSize().height + table.getTableHeader().getPreferredSize().height + 5)));
            p.setLayout(new java.awt.BorderLayout());
            p.add(scr, java.awt.BorderLayout.CENTER);
            p.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
            tablePanel.add(p);
        }
        panel.add(tablePanel, BorderLayout.CENTER);
        if (isODEData) {
            JPanel buttonPanel = new JPanel(new FlowLayout());
            JButton button = new JButton("Time Plot with Multiple Parameter Value Sets");
            buttonPanel.add(button);
            panel.add(buttonPanel, BorderLayout.SOUTH);
            button.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    mainViewer.showTimePlotMultipleScans(dataManager);
                }
            });
        } else {
            pdeDataViewer.setSimNameSimDataID(new ExportSpecs.SimNameSimDataID(getSimulation().getName(), getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), SimResultsViewer.getParamScanInfo(getSimulation(), getSelectedParamScanJobIndex())));
        }
        setParamChoicesPanel(panel);
    }
    // put things together
    setLayout(new java.awt.BorderLayout());
    add(getMainViewer(), java.awt.BorderLayout.CENTER);
    if (getSimulation().getScanCount() > 1) {
        add(getParamChoicesPanel(), java.awt.BorderLayout.SOUTH);
    }
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) Constant(cbit.vcell.math.Constant) ActionEvent(java.awt.event.ActionEvent) ExportSpecs(cbit.vcell.export.server.ExportSpecs) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) BorderLayout(java.awt.BorderLayout) BorderLayout(java.awt.BorderLayout) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) ListSelectionListener(javax.swing.event.ListSelectionListener) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier)

Example 8 with DefaultListSelectionModel

use of javax.swing.DefaultListSelectionModel in project jdk8u_jdk by JetBrains.

the class PathPlaceHolder method canPathsBeAdded.

/**
     * Used to test if a particular set of <code>TreePath</code>s can
     * be added. This will return true if <code>paths</code> is null (or
     * empty), or this object has no RowMapper, or nothing is currently selected,
     * or the selection mode is <code>DISCONTIGUOUS_TREE_SELECTION</code>, or
     * adding the paths to the current selection still results in a
     * contiguous set of <code>TreePath</code>s.
     */
protected boolean canPathsBeAdded(TreePath[] paths) {
    if (paths == null || paths.length == 0 || rowMapper == null || selection == null || selectionMode == TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION)
        return true;
    else {
        BitSet bitSet = new BitSet();
        DefaultListSelectionModel lModel = listSelectionModel;
        int anIndex;
        int counter;
        int min = lModel.getMinSelectionIndex();
        int max = lModel.getMaxSelectionIndex();
        TreePath[] tempPath = new TreePath[1];
        if (min != -1) {
            for (counter = min; counter <= max; counter++) {
                if (lModel.isSelectedIndex(counter))
                    bitSet.set(counter);
            }
        } else {
            tempPath[0] = paths[0];
            min = max = rowMapper.getRowsForPaths(tempPath)[0];
        }
        for (counter = paths.length - 1; counter >= 0; counter--) {
            if (paths[counter] != null) {
                tempPath[0] = paths[counter];
                int[] rows = rowMapper.getRowsForPaths(tempPath);
                if (rows == null) {
                    return false;
                }
                anIndex = rows[0];
                min = Math.min(anIndex, min);
                max = Math.max(anIndex, max);
                if (anIndex == -1)
                    return false;
                bitSet.set(anIndex);
            }
        }
        for (counter = min; counter <= max; counter++) if (!bitSet.get(counter))
            return false;
    }
    return true;
}
Also used : BitSet(java.util.BitSet) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel)

Example 9 with DefaultListSelectionModel

use of javax.swing.DefaultListSelectionModel in project pcgen by PCGen.

the class DescriptionInfoTab method createModels.

@Override
public ModelMap createModels(CharacterFacade character) {
    ModelMap models = new ModelMap();
    DefaultListModel listModel = new DefaultListModel();
    List<NoteInfoPane> notePaneList = new ArrayList<>();
    //$NON-NLS-1$
    PageItem firstPage = new PageItem(character, LanguageBundle.getString("in_descBiography"), bioPane);
    listModel.addElement(firstPage);
    //$NON-NLS-1$
    listModel.addElement(new PageItem(character, LanguageBundle.getString("in_portrait"), portraitPane));
    //$NON-NLS-1$
    listModel.addElement(new PageItem(character, LanguageBundle.getString("in_descCampHist"), histPane));
    models.put(ListModel.class, listModel);
    models.put(List.class, notePaneList);
    models.put(NoteListHandler.class, new NoteListHandler(character, listModel, notePaneList));
    ListSelectionModel model = new DefaultListSelectionModel();
    model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    model.setSelectionInterval(0, 0);
    models.put(ListSelectionModel.class, model);
    models.put(PageHandler.class, new PageHandler(model, firstPage));
    models.put(AddAction.class, new AddAction(character));
    return models;
}
Also used : ArrayList(java.util.ArrayList) DefaultListModel(javax.swing.DefaultListModel) ListSelectionModel(javax.swing.ListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) NoteInfoPane(pcgen.gui2.tabs.bio.NoteInfoPane)

Example 10 with DefaultListSelectionModel

use of javax.swing.DefaultListSelectionModel in project pcgen by PCGen.

the class DescriptionInfoTab method storeModels.

@Override
public void storeModels(ModelMap models) {
    pageList.setSelectionModel(new DefaultListSelectionModel());
    models.get(PageHandler.class).uninstall();
    models.get(NoteListHandler.class).uninstall();
}
Also used : DefaultListSelectionModel(javax.swing.DefaultListSelectionModel)

Aggregations

DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)12 ListSelectionModel (javax.swing.ListSelectionModel)4 ArrayList (java.util.ArrayList)2 ListSelectionListener (javax.swing.event.ListSelectionListener)2 TableColumnModel (javax.swing.table.TableColumnModel)2 CategoryTableModel (pcgen.gui2.tabs.ability.CategoryTableModel)2 DateRenderer (alma.acs.logging.table.renderer.DateRenderer)1 EntryTypeRenderer (alma.acs.logging.table.renderer.EntryTypeRenderer)1 InfoRenderer (alma.acs.logging.table.renderer.InfoRenderer)1 AlarmTableColumn (alma.acsplugins.alarmsystem.gui.table.AlarmTableModel.AlarmTableColumn)1 UndocAlarmTableModel (alma.acsplugins.alarmsystem.gui.undocumented.table.UndocAlarmTableModel)1 ROI (cbit.vcell.VirtualMicroscopy.ROI)1 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)1 ExportSpecs (cbit.vcell.export.server.ExportSpecs)1 RegionInfo (cbit.vcell.geometry.RegionImage.RegionInfo)1 Constant (cbit.vcell.math.Constant)1 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)1 BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 FontMetrics (java.awt.FontMetrics)1