use of javax.swing.DefaultCellEditor in project knetbuilder by Rothamsted.
the class InteractiveGenomicFilter method getSelection.
/**
* Queries graph selection and populates table with it.
*/
private void getSelection() {
// genes sorted by chromosome
Map<IntegerStringWrapper, List<ONDEXConcept>> map = new Hashtable<IntegerStringWrapper, List<ONDEXConcept>>();
// check for pick status
Set<ONDEXConcept> picked = new HashSet<ONDEXConcept>();
for (ONDEXConcept node : viewer.getPickedNodes()) {
picked.add(node);
}
int count = 0;
for (ONDEXConcept context : graph.getAllTags()) {
// check concept class of context
if (context.getOfType().getId().equalsIgnoreCase("Chromosome")) {
List<ONDEXConcept> list = new ArrayList<ONDEXConcept>();
for (ONDEXConcept concept : graph.getConceptsOfTag(context)) {
// only look for genes and QTLs
if ((concept.getOfType().getId().equals("Gene") || concept.getOfType().getId().equals("QTL")) && picked.contains(concept)) {
list.add(concept);
count++;
}
}
map.put(new IntegerStringWrapper(context.getId(), getDefaultNameForConcept(context)), list);
}
}
// static content of header
String[] columnNames = { HEADER_USE, HEADER_CHROMOSOME, HEADER_BEGIN, HEADER_END, HEADER_QTL };
// default data, every possible chromosome one row
Object[][] data = new Object[count][];
// first sort by chromosome
IntegerStringWrapper[] keys = map.keySet().toArray(new IntegerStringWrapper[0]);
Arrays.sort(keys);
int i = 0;
for (IntegerStringWrapper key : keys) {
// then sort by begin Attribute
ONDEXConcept[] genes = map.get(key).toArray(new ONDEXConcept[0]);
Arrays.sort(genes, new GDSComparator(anBegin));
for (ONDEXConcept c : genes) {
Object[] row = new Object[5];
row[0] = Boolean.valueOf(true);
row[1] = key;
row[2] = c.getAttribute(anBegin).getValue();
row[3] = c.getAttribute(anEnd).getValue();
ONDEXConcept qtl = graph.getConcept(key.getValue());
int chromNum = (Integer) qtl.getAttribute(anChromosome).getValue();
JComboBox qtlJBox = createQTLComboBox(chromNum);
DefaultCellEditor qtlEditor = new DefaultCellEditor(qtlJBox);
rm.addEditorForRow(i, qtlEditor);
// TODO select the correct QTL from list, and not just the first
// one
row[4] = qtlJBox.getItemAt(0);
data[i] = row;
i++;
}
}
setupTable(data, columnNames, rm);
}
use of javax.swing.DefaultCellEditor in project knetbuilder by Rothamsted.
the class InteractiveGenomicFilter method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
/*
* change graph to genomic view
*/
if (cmd.equals("view")) {
switchToGenomicLayout();
if (viewer.isIcon()) {
try {
viewer.setIcon(false);
} catch (PropertyVetoException pve) {
// ignore, can't help
}
}
} else /*
* populate table with user selection
*/
if (cmd.equals("update")) {
panelConfig.removeAll();
getSelection();
panelConfig.add(new JScrollPane(searchTable));
this.revalidate();
} else /*
* insert a default row
*/
if (cmd.equals("insert")) {
insertRow();
} else /*
* reset table to default
*/
if (cmd.equals("clear")) {
panelConfig.removeAll();
defaultTable();
panelConfig.add(new JScrollPane(searchTable));
this.revalidate();
} else if (cmd.equals("hide")) {
StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
OVTK2Desktop desktop = OVTK2Desktop.getInstance();
desktop.setRunningProcess(this.getName());
if (toggleSearchResults) {
// preserve for making visible again
invisibleConcepts = new HashSet<ONDEXConcept>();
invisibleRelations = new HashSet<ONDEXRelation>();
// set relations that are NOT on a path to invisible
for (ONDEXRelation r : graph.getEdges()) {
if (rels != null && !rels.contains(r)) {
graph.setVisibility(r, false);
invisibleRelations.add(r);
}
}
// now set concepts that become unconnected to invisible
for (ONDEXConcept c : graph.getVertices()) {
if (graph.getNeighborCount(c) == 0) {
graph.setVisibility(c, false);
invisibleConcepts.add(c);
}
}
toggleSearchResults = false;
} else {
graph.setVisibility(invisibleConcepts, true);
graph.setVisibility(invisibleRelations, true);
toggleSearchResults = true;
}
viewer.getVisualizationViewer().getModel().fireStateChanged();
edit.end();
viewer.getUndoManager().addEdit(edit);
desktop.getOVTK2Menu().updateUndoRedo(viewer);
desktop.notifyTerminationOfProcess();
} else /*
* do the search
*/
if (cmd.equals("searchRegion")) {
StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
OVTK2Desktop desktop = OVTK2Desktop.getInstance();
desktop.setRunningProcess(this.getName());
toggleSearchResults = true;
invisibleConcepts = null;
invisibleRelations = null;
performSearch();
// if keywords are provided set not related genes to invisible
if (!textFieldSearch.getText().trim().isEmpty())
hideGenesButton.doClick();
edit.end();
viewer.getUndoManager().addEdit(edit);
desktop.getOVTK2Menu().updateUndoRedo(viewer);
desktop.notifyTerminationOfProcess();
if (viewer.isIcon()) {
try {
viewer.setIcon(false);
} catch (PropertyVetoException pve) {
// ignore, can't help
}
}
} else /*
* do the search
*/
if (cmd.equals("searchGenome")) {
// get search keyword
String keyword = textFieldSearch.getText();
if (!keyword.isEmpty()) {
toggleSearchResults = true;
invisibleConcepts = null;
invisibleRelations = null;
StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
OVTK2Desktop desktop = OVTK2Desktop.getInstance();
desktop.setRunningProcess(this.getName());
// set first entire graph to invisible
setGraphVisible(false);
searchGenome(keyword);
// new Attribute layout
GDSPositionLayout layout = new GDSPositionLayout(viewer);
// propagate change to viewer
VisualizationModel<ONDEXConcept, ONDEXRelation> model = viewer.getVisualizationViewer().getModel();
model.setGraphLayout(layout);
model.fireStateChanged();
viewer.center();
edit.end();
viewer.getUndoManager().addEdit(edit);
desktop.getOVTK2Menu().updateUndoRedo(viewer);
desktop.notifyTerminationOfProcess();
if (viewer.isIcon()) {
try {
viewer.setIcon(false);
} catch (PropertyVetoException pve) {
// ignore, can't help
}
}
}
} else /*
* toggle inter-relations
*/
if (cmd.equals("relations")) {
StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
OVTK2Desktop desktop = OVTK2Desktop.getInstance();
desktop.setRunningProcess(this.getName());
RelationType rt = graph.getMetaData().getRelationType("enc");
toggleRelations = !toggleRelations;
for (ONDEXRelation r : graph.getRelationsOfRelationType(rt)) {
graph.setVisibility(r, toggleRelations);
}
viewer.getVisualizationViewer().getModel().fireStateChanged();
edit.end();
viewer.getUndoManager().addEdit(edit);
desktop.getOVTK2Menu().updateUndoRedo(viewer);
desktop.notifyTerminationOfProcess();
} else /*
* actions that happen when changing chromosome or QTL column
*/
if (e.getSource() instanceof JComboBox) {
Object obj = ((JComboBox) e.getSource()).getSelectedItem();
if (obj instanceof String || searchTable == null) {
return;
}
DefaultTableModel model = (DefaultTableModel) searchTable.getModel();
int rowNum = searchTable.getSelectedRow();
int colNum = searchTable.getSelectedColumn();
IntegerStringWrapper isw = (IntegerStringWrapper) obj;
if (colNum == 1) {
ONDEXConcept chrom = graph.getConcept(isw.getValue());
// ignore scaffolds
if (chrom.getAttribute(anChromosome) != null) {
int chromNum = (Integer) chrom.getAttribute(anChromosome).getValue();
JComboBox qtlBox = createQTLComboBox(chromNum);
DefaultCellEditor qtlEditor = new DefaultCellEditor(qtlBox);
rm.addEditorForRow(rowNum, qtlEditor);
}
} else // QTL column
if (colNum == 4) {
ONDEXConcept qtl = graph.getConcept(isw.getValue());
// TODO: why is colNum 4 sometimes of Type Chromosome?
if (qtl.getOfType().getId().equals("QTL")) {
Integer newBeg = (Integer) qtl.getAttribute(anBegin).getValue();
Integer newEnd = (Integer) qtl.getAttribute(anEnd).getValue();
model.setValueAt(newBeg, rowNum, 2);
model.setValueAt(newEnd, rowNum, 3);
} else {
// System.out.println("COLUMN IS 4 BUT ELEMENT: "+
// qtl.getOfType().getId());
}
}
}
}
use of javax.swing.DefaultCellEditor in project knetbuilder by Rothamsted.
the class InteractiveGenomicFilter method insertRow.
/**
* Inserts a default row at the end of table.
*/
private void insertRow() {
DefaultTableModel model = (DefaultTableModel) searchTable.getModel();
Object[] row = new Object[5];
row[0] = Boolean.valueOf(true);
row[1] = chromosomeBox.getItemAt(0);
row[2] = Integer.valueOf(1);
row[3] = Integer.valueOf(100000);
JComboBox qtlJBox = chromosome2qtl.get(((IntegerStringWrapper) chromosomeBox.getItemAt(0)).getValue());
DefaultCellEditor qtlEditor = new DefaultCellEditor(qtlJBox);
rm.addEditorForRow(model.getRowCount(), qtlEditor);
row[4] = qtlJBox.getItemAt(0);
model.insertRow(model.getRowCount(), row);
}
use of javax.swing.DefaultCellEditor in project Mapillary by JOSM.
the class MapillaryExpertFilterDialog method build.
/**
* Builds the GUI.
*/
private void build() {
userTable = new UserTable(filterModel);
userTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
userTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
userTable.setSelectionModel(filterModel.getSelectionModel());
TableHelper.adjustColumnWidth(userTable, 0, false);
TableHelper.adjustColumnWidth(userTable, 1, false);
TableHelper.adjustColumnWidth(userTable, 3, false);
TableHelper.adjustColumnWidth(userTable, 4, false);
userTable.setDefaultRenderer(Boolean.class, new BooleanRenderer());
userTable.setDefaultRenderer(String.class, new StringRenderer());
userTable.setDefaultEditor(String.class, new DefaultCellEditor(new DisableShortcutsOnFocusGainedTextField()));
// Toggle filter "enabled" on Enter
InputMapUtils.addEnterAction(userTable, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
int index = userTable.getSelectedRow();
if (index >= 0) {
Filter filter = filterModel.getValue(index);
filterModel.setValueAt(!filter.enable, index, MapillaryFilterTableModel.COL_ENABLED);
}
}
});
// Toggle filter "hiding" on Spacebar
InputMapUtils.addSpacebarAction(userTable, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
int index = userTable.getSelectedRow();
if (index >= 0) {
Filter filter = filterModel.getValue(index);
filterModel.setValueAt(!filter.hiding, index, MapillaryFilterTableModel.COL_HIDING);
}
}
});
List<FilterAction> actions = Arrays.asList(addAction, editAction, deleteAction, moveUpAction, moveDownAction, sortAction, reverseAction);
for (FilterAction action : actions) {
TableHelper.adaptTo(action, filterModel);
TableHelper.adaptTo(action, filterModel.getSelectionModel());
action.updateEnabledState();
}
createLayout(userTable, true, actions.stream().map(a -> new SideButton(a, false)).collect(Collectors.toList()));
}
use of javax.swing.DefaultCellEditor in project knime-base by knime.
the class ShapeManagerNodeDialogPane method columnChanged.
private void columnChanged(final String column) {
final LinkedHashMap<DataCell, Shape> domMap = m_map.get(column);
TableModel tableModel = new DefaultTableModel() {
private final DataCell[] m_valueNames = new DataCell[domMap.size()];
{
int row = 0;
for (DataCell cell : domMap.keySet()) {
m_valueNames[row] = cell;
row++;
}
}
@Override
public String getColumnName(final int columnIdx) {
if (columnIdx == 1) {
return "Shapes";
} else {
return "Values of " + column;
}
}
@Override
public boolean isCellEditable(final int row, final int columnIdx) {
return (columnIdx == 1);
}
@Override
public int getRowCount() {
return domMap.size();
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Class<?> getColumnClass(final int columnIndex) {
if (columnIndex == 1) {
return Shape.class;
} else {
return DataCell.class;
}
}
@Override
public Object getValueAt(final int row, final int columnIndex) {
if (columnIndex == 1) {
return domMap.get(m_valueNames[row]);
} else {
return m_valueNames[row];
}
}
@Override
public void setValueAt(final Object aValue, final int row, final int columnIdx) {
assert aValue instanceof Shape;
assert columnIdx == 1;
domMap.put(m_valueNames[row], (Shape) aValue);
}
};
m_valueTable.setModel(tableModel);
m_valueTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new ShapeSelectionComboBox()));
m_valueTable.getColumnModel().getColumn(1).setCellRenderer(new ShapeSelectionComboBoxRenderer());
}
Aggregations