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]);
}
}
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);
}
}
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;
}
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;
}
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();
}
Aggregations