/** * @param features * @param qualifiersToTransfer * @param key * @param sameKey * @param isDatabaseEntry * @param geneNames * @return */ private static String[] transfer( final FeatureVector features, final QualifierVector qualifiersToTransfer, final String key, final boolean sameKey, final boolean overwrite, final boolean isDatabaseEntry, String[] geneNames, final StringBuffer genesUpdated) { final TransferFeaturePredicate predicate = new TransferFeaturePredicate(key, sameKey, isDatabaseEntry, geneNames); for (int i = 0; i < features.size(); i++) { Feature thisFeature = features.elementAt(i); if (predicate.testPredicate(thisFeature)) { StringBuffer qualifierBuffer = new StringBuffer(); for (int j = 0; j < qualifiersToTransfer.size(); j++) { Qualifier newQualifier = qualifiersToTransfer.elementAt(j); String qualifierName = newQualifier.getName(); try { if (overwrite) { thisFeature.setQualifier(newQualifier); qualifierBuffer.append( " " + qualifierName + " (overwritten)\n" + parseStringVector(newQualifier.getValues())); } else { final StringVector oldValues; if (thisFeature.getQualifierByName(newQualifier.getName()) == null) oldValues = null; else oldValues = thisFeature.getQualifierByName(newQualifier.getName()).getValues(); final Qualifier newQualifierTmp = getQualifierWithoutDuplicateValues(newQualifier, oldValues); if (newQualifierTmp == null) continue; thisFeature.addQualifierValues(newQualifierTmp); qualifierBuffer.append( " " + qualifierName + " (added)\n" + parseStringVector(newQualifier.getValues())); } } catch (Exception e1) { e1.printStackTrace(); } } geneNames = removeArrayElement(geneNames, predicate.getGeneName()); if (qualifierBuffer.length() > 0) genesUpdated.append( thisFeature.getSystematicName() + " (" + key + ")\n" + qualifierBuffer); } } return geneNames; }
private void updateFromFeature(Feature feature) { GridBagConstraints c = new GridBagConstraints(); JPanel gridPanel = new JPanel(new GridBagLayout()); gridPanel.setBackground(Color.white); // // literature & dbxref literatureTextArea = new QualifierTextArea(); literatureTextArea.setBorder(BorderFactory.createLineBorder(Color.gray)); dbxrefTextArea = new QualifierTextArea(); dbxrefTextArea.setBorder(BorderFactory.createLineBorder(Color.gray)); literatureTextArea .getDocument() .addDocumentListener(new TextAreaDocumentListener(literatureTextArea)); dbxrefTextArea.getDocument().addDocumentListener(new TextAreaDocumentListener(dbxrefTextArea)); final QualifierVector qualifiers = feature.getQualifiers().copy(); final StringBuffer litBuffer = new StringBuffer(); final StringBuffer dbxrefBuffer = new StringBuffer(); for (int i = 0; i < qualifiers.size(); ++i) { Qualifier this_qualifier = (Qualifier) qualifiers.elementAt(i); if (this_qualifier.getName().equals("literature")) appendToBuffer(this_qualifier.getValues(), litBuffer); else if (this_qualifier.getName().equalsIgnoreCase("Dbxref")) appendToBuffer(this_qualifier.getValues(), dbxrefBuffer); } c.gridx = 0; c.gridy = 0; c.ipadx = 5; c.ipady = 5; c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.NONE; gridPanel.add(new JLabel("Literature"), c); c.gridx = 1; gridPanel.add(literatureTextArea, c); c.gridx = 0; c.gridy = 1; gridPanel.add(new JLabel("Dbxref"), c); c.gridx = 1; gridPanel.add(dbxrefTextArea, c); add(gridPanel); literatureTextArea.setText(litBuffer.toString() + "\n"); dbxrefTextArea.setText(dbxrefBuffer.toString() + "\n"); }
/** * Return a qualifier copy of the qualifier provided that does not contain any of the values in * the StringVector. * * @param newQualifier * @param oldValues * @return * @throws InvalidRelationException */ protected static Qualifier getQualifierWithoutDuplicateValues( final Qualifier qualifier, final StringVector values) throws InvalidRelationException { final Qualifier newQualifier; if (values == null || values.size() < 1) newQualifier = qualifier; else { StringVector newValues = qualifier.getValues(); StringVector valuesToAdd = new StringVector(); for (int k = 0; k < newValues.size(); k++) { if (!values.contains(newValues.get(k))) { if (qualifier.getName().equals("history")) { if (!uk.ac.sanger.artemis.components.genebuilder.cv.HistoryBox.contains( values, (String) newValues.get(k))) valuesToAdd.add(newValues.get(k)); } else valuesToAdd.add(newValues.get(k)); } } if (valuesToAdd.size() == 0) return null; newQualifier = new Qualifier(qualifier.getName(), valuesToAdd); } return newQualifier; }
/** * Set up the expander button to display qualifier values. * * @param butt - expander button * @param qualifier - the qualifer that is being displayed * @param qualifierValueBox - Box containing the values * @param qualifierNameCheckBox - JCheckBox for the given qualifier * @param pane * @return */ private Vector<JCheckBox> setExpanderButton( final JButton butt, final Qualifier qualifier, final Box qualifierValueBox, final JCheckBox qualifierNameCheckBox) { butt.setMargin(new Insets(0, 0, 0, 0)); butt.setHorizontalAlignment(SwingConstants.RIGHT); butt.setHorizontalTextPosition(SwingConstants.RIGHT); butt.setBorderPainted(false); butt.setFont(butt.getFont().deriveFont(Font.BOLD)); butt.setForeground(TransferAnnotationTool.STEEL_BLUE); butt.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (butt.getText().equals("+")) butt.setText("-"); else butt.setText("+"); qualifierValueBox.setVisible(butt.getText().equals("-")); revalidate(); } }); // set-up qualifier values list qualifierValueBox.setVisible(false); final Vector<JCheckBox> qualifierValuesCheckBox = new Vector<JCheckBox>(); final StringVector values = qualifier.getValues(); if (values != null) { for (int i = 0; i < values.size(); i++) { final JCheckBox cb = new JCheckBox(values.get(i), qualifierNameCheckBox.isSelected()); cb.setFont(cb.getFont().deriveFont(Font.ITALIC)); qualifierValueBox.add(cb); qualifierValuesCheckBox.add(cb); } } return qualifierValuesCheckBox; }
/** * Contruct a component for a similarity line * * @param similarity * @param similarityString */ protected SimilarityTable(final Qualifier simQualifier, final DatabaseDocument doc) { this.origQualifiers = new QualifierVector(); this.origQualifiers.add(simQualifier); infoLevelButton.setOpaque(false); infoLevelButton.setHorizontalAlignment(SwingConstants.LEFT); tableData.setSize(NUMBER_COLUMNS); tableData.setElementAt(ORGANISM_COL, 0); tableData.setElementAt(HIT_COL, 1); tableData.setElementAt(HIT_DBXREF_COL, 2); tableData.setElementAt(DESCRIPTION_COL, 3); tableData.setElementAt(EVALUE_COL, 4); tableData.setElementAt(LENGTH_COL, 5); tableData.setElementAt(ID_COL, 6); tableData.setElementAt(QUERY_COL, 7); tableData.setElementAt(SUBJECT_COL, 8); tableData.setElementAt(SCORE_COL, 9); tableData.setElementAt(OVERLAP_COL, 10); tableData.setElementAt(METHOD_COL, 11); tableData.setElementAt(REMOVE_BUTTON_COL, 12); // add rows of similarity StringVector sims = simQualifier.getValues(); for (int i = 0; i < sims.size(); i++) rowData.add(getRowData((String) sims.get(i), tableData)); JTable similarityTable = new JTable(rowData, tableData); setTable(similarityTable); // set hand cursor similarityTable.addMouseMotionListener( new MouseMotionAdapter() { private Cursor handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); public void mouseMoved(MouseEvent e) { int col = table.columnAtPoint(e.getPoint()); String colName = table.getColumnName(col); if (colName.equals(HIT_COL) || colName.equals(HIT_DBXREF_COL) || colName.equals(REMOVE_BUTTON_COL)) table.setCursor(handCursor); else table.setCursor(Cursor.getDefaultCursor()); } }); similarityTable.setColumnSelectionAllowed(false); similarityTable.setRowSelectionAllowed(true); packColumn(similarityTable, getColumnIndex(LENGTH_COL), 4); packColumn(similarityTable, getColumnIndex(EVALUE_COL), 4); packColumn(similarityTable, getColumnIndex(ID_COL), 4); packColumn(similarityTable, getColumnIndex(HIT_COL), 6); packColumn(similarityTable, getColumnIndex(HIT_DBXREF_COL), 6); final TableColumn[] hideColumns = new TableColumn[5]; hideColumns[0] = similarityTable.getColumn(QUERY_COL); hideColumns[1] = similarityTable.getColumn(SUBJECT_COL); hideColumns[2] = similarityTable.getColumn(SCORE_COL); hideColumns[3] = similarityTable.getColumn(OVERLAP_COL); hideColumns[4] = similarityTable.getColumn(METHOD_COL); for (int i = 0; i < hideColumns.length; i++) { hideColumns[i].setMinWidth(0); hideColumns[i].setMaxWidth(0); } infoLevelButton.addActionListener( new ActionListener() { private boolean show = true; public void actionPerformed(ActionEvent e) { // change the column size for (int i = 0; i < hideColumns.length; i++) { if (show) packColumn(getTable(), getColumnIndex((String) hideColumns[i].getHeaderValue()), 2); else { hideColumns[i].setMinWidth(0); hideColumns[i].setMaxWidth(0); } } show = !show; if (infoLevelButton.getText().equals("Details")) infoLevelButton.setText("Hide Details"); else infoLevelButton.setText("Details"); } }); TableModel tableModel = getTable().getModel(); // remove button column TableColumn col = getTable().getColumn(REMOVE_BUTTON_COL); col.setMinWidth(35); col.setMaxWidth(40); col.setPreferredWidth(40); final SimilarityRenderer renderer = new SimilarityRenderer(); for (int columnIndex = 0; columnIndex < tableModel.getColumnCount(); columnIndex++) { col = getTable().getColumnModel().getColumn(columnIndex); col.setCellRenderer(renderer); col.setCellEditor(new CellEditing(new JTextField())); } col = getTable().getColumn(HIT_COL); col.setCellEditor( new LinkEditor(new JCheckBox(), (DefaultTableModel) getTable().getModel(), null)); col = getTable().getColumn(HIT_DBXREF_COL); col.setCellEditor( new LinkEditor(new JCheckBox(), (DefaultTableModel) getTable().getModel(), null)); // remove JButton column col = getTable().getColumn(REMOVE_BUTTON_COL); col.setCellEditor( new ButtonEditor(new JCheckBox(), (DefaultTableModel) getTable().getModel(), "X", doc)); }