Search in sources :

Example 1 with IntegerStringWrapper

use of net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper in project knetbuilder by Rothamsted.

the class HtmlComboBoxRenderer method getListCellRendererComponent.

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }
    // Set the text wrapped as html.
    String text = "";
    if (value != null) {
        if (value instanceof IntegerStringWrapper) {
            IntegerStringWrapper wrapper = (IntegerStringWrapper) value;
            text = wrapper.toString();
            setToolTipText(wrapper.getDescription());
        } else if (value instanceof MetaDataWrapper) {
            MetaDataWrapper wrapper = (MetaDataWrapper) value;
            text = wrapper.toString();
            setToolTipText(wrapper.getDescription());
        } else {
            text = value.toString();
            setToolTipText(text);
            if (text.length() > 15)
                text = text.substring(0, 15) + "...";
        }
    }
    setText("<html>" + text + "</html>");
    return this;
}
Also used : IntegerStringWrapper(net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper) MetaDataWrapper(net.sourceforge.ondex.ovtk2.ui.toolbars.MenuGraphSearchBox.MetaDataWrapper)

Example 2 with IntegerStringWrapper

use of net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper in project knetbuilder by Rothamsted.

the class InteractiveGenomicFilter method defaultTable.

/**
 * Populate default table with row specific QTL cell editor.
 */
private void defaultTable() {
    // static content of header
    String[] columnNames = { HEADER_USE, HEADER_CHROMOSOME, HEADER_BEGIN, HEADER_END, HEADER_QTL };
    int limit = 5;
    if (chromosomeBox.getItemCount() < 5) {
        limit = chromosomeBox.getItemCount();
    }
    // default data, every possible chromosome one row
    Object[][] data = new Object[limit][];
    for (int i = 0; i < limit; i++) {
        Object[] row = new Object[5];
        IntegerStringWrapper ch = (IntegerStringWrapper) chromosomeBox.getItemAt(i);
        row[0] = Boolean.valueOf(true);
        row[1] = ch;
        row[2] = Integer.valueOf(1);
        row[3] = Integer.valueOf(100000);
        JComboBox qtlJBox = chromosome2qtl.get(ch.getValue());
        if (qtlJBox != null)
            row[4] = qtlJBox.getItemAt(0);
        else
            row[4] = "NA";
        DefaultCellEditor qtlEditor = new DefaultCellEditor(qtlJBox);
        rm.addEditorForRow(i, qtlEditor);
        data[i] = row;
    }
    setupTable(data, columnNames, rm);
}
Also used : IntegerStringWrapper(net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper) JComboBox(javax.swing.JComboBox) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 3 with IntegerStringWrapper

use of net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper 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);
}
Also used : IntegerStringWrapper(net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper) JComboBox(javax.swing.JComboBox) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) DefaultCellEditor(javax.swing.DefaultCellEditor) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 4 with IntegerStringWrapper

use of net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper in project knetbuilder by Rothamsted.

the class InteractiveGenomicFilter method createQTLComboBox.

/**
 * Creates a JComboBox containing all QTLs for the given Chromosome The
 * validation if a QTL is located on the given chromosome number is based on
 * comparison of AttributeName "Chromosome" (Integer)
 *
 * @param chromosome
 * @return
 */
private JComboBox createQTLComboBox(int chromosome) {
    JComboBox qtlBox = new JComboBox();
    qtlBox.removeAllItems();
    qtlBox.addItem("...");
    // iterate over all QTLs
    for (ONDEXConcept c : graph.getConceptsOfConceptClass(ccQTL)) {
        // get QTL's AttributeName "Chromosome"
        int qtlPos = (Integer) c.getAttribute(anChromosome).getValue();
        // check if QTL is on given chromosome
        if (qtlPos == chromosome) {
            // System.out.println("QTL was added to chromosome");
            qtlBox.addItem(new IntegerStringWrapper(c.getId(), getDefaultNameForConcept(c)));
        }
    }
    qtlBox.revalidate();
    qtlBox.addActionListener(this);
    return qtlBox;
}
Also used : IntegerStringWrapper(net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) JComboBox(javax.swing.JComboBox)

Example 5 with IntegerStringWrapper

use of net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper in project knetbuilder by Rothamsted.

the class InteractiveGenomicFilter method addContextToComboBox.

/**
 * Adds the context (Chromosome) items to the drop-down list and sorts them
 * alpha-numerically
 *
 * @param chromosomeBox
 *            JComboBox for category
 */
private void addContextToComboBox(JComboBox chromosomeBox) {
    // add context items to combo box
    chromosomeBox.removeAllItems();
    if (ccGene != null && ccChromosome != null) {
        Set<ONDEXConcept> viewGene = graph.getConceptsOfConceptClass(ccGene);
        Set<ONDEXConcept> viewChro = graph.getConceptsOfConceptClass(ccChromosome);
        Set<ONDEXConcept> viewScaf = graph.getConceptsOfConceptClass(ccScaffold);
        // iterate over all chromosomes which are used as context
        for (ONDEXConcept c : BitSetFunctions.or(viewChro, viewScaf)) {
            // take chromosome only if it's the context of any gene
            if (BitSetFunctions.and(graph.getConceptsOfTag(c), viewGene).size() == 0)
                continue;
            chromosomeBox.addItem(new IntegerStringWrapper(c.getId(), getDefaultNameForConcept(c)));
            // QTLs are only on chromosomes and not on scaffolds
            if (c.getOfType().equals(ccChromosome)) {
                JComboBox jCB = createQTLComboBox((Integer) c.getAttribute(anChromosome).getValue());
                chromosome2qtl.put(c.getId(), jCB);
            }
        }
        sortContexts(chromosomeBox);
        chromosomeBox.revalidate();
    }
}
Also used : IntegerStringWrapper(net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) JComboBox(javax.swing.JComboBox)

Aggregations

IntegerStringWrapper (net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper)13 ONDEXConcept (net.sourceforge.ondex.core.ONDEXConcept)10 JComboBox (javax.swing.JComboBox)6 ArrayList (java.util.ArrayList)5 DefaultCellEditor (javax.swing.DefaultCellEditor)3 DefaultTableModel (javax.swing.table.DefaultTableModel)3 ONDEXRelation (net.sourceforge.ondex.core.ONDEXRelation)3 OVTK2Desktop (net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop)3 HashSet (java.util.HashSet)2 StateEdit (javax.swing.undo.StateEdit)2 VisibilityUndo (net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)2 GDSPositionLayout (net.sourceforge.ondex.ovtk2.layout.GDSPositionLayout)2 MetaDataWrapper (net.sourceforge.ondex.ovtk2.ui.toolbars.MenuGraphSearchBox.MetaDataWrapper)2 PropertyVetoException (java.beans.PropertyVetoException)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Vector (java.util.Vector)1 BorderFactory (javax.swing.BorderFactory)1 JScrollPane (javax.swing.JScrollPane)1