From 3aa725b66b162b84fe8b4ccfbc64d0aa2b99b670 Mon Sep 17 00:00:00 2001 From: tjc <tjc@ee4ac58c-ac51-4696-9907-e4b3aa274f04> Date: Wed, 20 Jun 2007 15:23:29 +0000 Subject: [PATCH] implement opening gene editors for linked features in a cluster git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@6131 ee4ac58c-ac51-4696-9907-e4b3aa274f04 --- .../ortholog/AbstractMatchTable.java | 122 +++++++++++++++++- .../genebuilder/ortholog/MatchPanel.java | 8 +- .../genebuilder/ortholog/OrthologTable.java | 74 +++++------ 3 files changed, 157 insertions(+), 47 deletions(-) diff --git a/uk/ac/sanger/artemis/components/genebuilder/ortholog/AbstractMatchTable.java b/uk/ac/sanger/artemis/components/genebuilder/ortholog/AbstractMatchTable.java index 745c5d008..b2a2d6b3a 100644 --- a/uk/ac/sanger/artemis/components/genebuilder/ortholog/AbstractMatchTable.java +++ b/uk/ac/sanger/artemis/components/genebuilder/ortholog/AbstractMatchTable.java @@ -48,7 +48,11 @@ import javax.swing.table.DefaultTableModel; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; +import uk.ac.sanger.artemis.components.genebuilder.GeneEdit; +import uk.ac.sanger.artemis.io.DatabaseDocumentEntry; +import uk.ac.sanger.artemis.io.EntryInformationException; import uk.ac.sanger.artemis.io.QualifierVector; +import uk.ac.sanger.artemis.util.DatabaseDocument; abstract class AbstractMatchTable { @@ -212,12 +216,11 @@ abstract class AbstractMatchTable { public void actionPerformed(ActionEvent e) { - fireEditingStopped(); - + fireEditingStopped(); } }); } - + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { @@ -264,6 +267,119 @@ abstract class AbstractMatchTable catch(ArrayIndexOutOfBoundsException e){} } } + + + + + + + + /** + * + */ + protected class LinkEditor extends DefaultCellEditor + { + /** */ + private static final long serialVersionUID = 1L; + protected JButton linkButton = new JButton(); + private boolean isPushed; + private Color fgLinkColor = Color.BLUE; + private DatabaseDocument doc; + + public LinkEditor(JCheckBox checkBox, final DefaultTableModel tableModel, + DatabaseDocument doc) + { + super(checkBox); + this.doc = doc; + + linkButton.setBorderPainted(false); + linkButton.setOpaque(false); + + + linkButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + fireEditingStopped(); + } + }); + } + + private DatabaseDocumentEntry makeEntry(final String schema, + final String uniquename) + { + DatabaseDocumentEntry db_entry = null; + DatabaseDocument newdoc = new DatabaseDocument(doc, + uniquename, schema, true); + + try + { + db_entry = new DatabaseDocumentEntry(newdoc, null); + } + catch(EntryInformationException e) + { + e.printStackTrace(); + } + catch(IOException e) + { + e.printStackTrace(); + } + return db_entry; + } + + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, int row, int column) + { + linkButton.setText((String)value); + if (isSelected) + { + linkButton.setForeground(fgLinkColor); + linkButton.setBackground(table.getSelectionBackground()); + } + else + { + linkButton.setForeground(fgLinkColor); + linkButton.setBackground(table.getBackground()); + } + + isPushed = true; + return linkButton; + } + + public Object getCellEditorValue() + { + String link = linkButton.getText(); + if(isPushed) + { + // open gene editor for this link + + String reference[] = link.split(":"); + DatabaseDocumentEntry entry = makeEntry(reference[0], reference[1]); + entry.setReadOnly(true); + GeneEdit.showGeneEditor(reference[0], reference[1], entry); + + isChanged = true; + return link; + } + isPushed = false; + return link; + } + + public boolean stopCellEditing() + { + isPushed = false; + return super.stopCellEditing(); + } + + protected void fireEditingStopped() + { + try + { + super.fireEditingStopped(); + } + catch(ArrayIndexOutOfBoundsException e){} + } + } // //http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html diff --git a/uk/ac/sanger/artemis/components/genebuilder/ortholog/MatchPanel.java b/uk/ac/sanger/artemis/components/genebuilder/ortholog/MatchPanel.java index 1155b3cc1..ad9afe538 100644 --- a/uk/ac/sanger/artemis/components/genebuilder/ortholog/MatchPanel.java +++ b/uk/ac/sanger/artemis/components/genebuilder/ortholog/MatchPanel.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/genebuilder/ortholog/MatchPanel.java,v 1.6 2007-06-13 14:17:32 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/genebuilder/ortholog/MatchPanel.java,v 1.7 2007-06-20 15:23:29 tjc Exp $ */ package uk.ac.sanger.artemis.components.genebuilder.ortholog; @@ -151,7 +151,11 @@ public class MatchPanel extends JPanel //{ if(hide_show_ortho == null) hide_show_ortho = new JButton("-"); - orthologTable = new OrthologTable(orthoQualifier); + + DocumentEntry entry = (DocumentEntry)feature.getEmblFeature().getEntry(); + DatabaseDocument doc = (DatabaseDocument)entry.getDocument(); + + orthologTable = new OrthologTable(doc, orthoQualifier); addHideShowButton(orthologTable.getTable(), hide_show_ortho); xBox.add(hide_show_ortho); editableComponents.add(orthologTable); diff --git a/uk/ac/sanger/artemis/components/genebuilder/ortholog/OrthologTable.java b/uk/ac/sanger/artemis/components/genebuilder/ortholog/OrthologTable.java index a482f3c03..8d735e86a 100644 --- a/uk/ac/sanger/artemis/components/genebuilder/ortholog/OrthologTable.java +++ b/uk/ac/sanger/artemis/components/genebuilder/ortholog/OrthologTable.java @@ -43,17 +43,18 @@ import javax.swing.table.TableModel; import uk.ac.sanger.artemis.io.Qualifier; import uk.ac.sanger.artemis.io.QualifierVector; +import uk.ac.sanger.artemis.util.DatabaseDocument; public class OrthologTable extends AbstractMatchTable { - private int NUMBER_COLUMNS = 4; + private int NUMBER_COLUMNS = 3; private Vector rowData = new Vector(); private Vector tableData = new Vector(NUMBER_COLUMNS); private JTable orthologTable; private JButton infoLevelButton = new JButton("Details"); private Qualifier origQualifier; private boolean isChanged = false; - + // // column headings final static String ORGANISM_COL = "Organism"; @@ -66,32 +67,29 @@ public class OrthologTable extends AbstractMatchTable * @param similarity * @param similarityString */ - protected OrthologTable(final Qualifier origQualifier) + protected OrthologTable(final DatabaseDocument doc, + final Qualifier origQualifier) { this.origQualifier = origQualifier; infoLevelButton.setOpaque(false); tableData.setSize(NUMBER_COLUMNS); - tableData.setElementAt(ORGANISM_COL,0); - tableData.setElementAt(ORTHO_COL,1); - tableData.setElementAt(DESCRIPTION_COL,2); - tableData.setElementAt(REMOVE_BUTTON_COL,3); + tableData.setElementAt(ORTHO_COL,0); + tableData.setElementAt(DESCRIPTION_COL,1); + tableData.setElementAt(REMOVE_BUTTON_COL,2); // add row data Vector thisRowData = new Vector(); - thisRowData.add("organism"); - thisRowData.add("blah"); + thisRowData.add("Bpseudomallei:BPSL0003"); thisRowData.add("blah blah"); rowData.add(thisRowData); Vector thisRowData2 = new Vector(); - thisRowData2.add("organism2"); - thisRowData2.add("blah2"); + thisRowData2.add("Bpseudomallei:BPSL2915"); thisRowData2.add("blah blah2"); rowData.add(thisRowData2); Vector thisRowData3 = new Vector(); - thisRowData3.add("organism3"); - thisRowData3.add("blah3"); + thisRowData3.add("schema:id"); thisRowData3.add("blah blah3"); rowData.add(thisRowData3); @@ -124,6 +122,11 @@ public class OrthologTable extends AbstractMatchTable col = orthologTable.getColumn(REMOVE_BUTTON_COL); col.setCellEditor(new ButtonEditor(new JCheckBox(), (DefaultTableModel)orthologTable.getModel())); + + // orthologue link + col = orthologTable.getColumn(ORTHO_COL); + col.setCellEditor(new LinkEditor(new JCheckBox(), + (DefaultTableModel)orthologTable.getModel(), doc)); } protected boolean isQualifierChanged() @@ -148,20 +151,15 @@ public class OrthologTable extends AbstractMatchTable private static final long serialVersionUID = 1L; private int minHeight = -1; - private final JTextArea orthologTextArea = new JTextArea(); - private final JTextArea organismTextArea = new JTextArea(); + private final JLabel orthologLabel = new JLabel(); private final JTextArea descriptionTextArea = new JTextArea(); private final JLabel buttRemove = new JLabel("X"); private Color fgColor = new Color(139,35,35); + private Color fgLinkColor = Color.BLUE; public OrthologRenderer() { - - organismTextArea.setLineWrap(true); - organismTextArea.setWrapStyleWord(true); - - orthologTextArea.setLineWrap(true); - orthologTextArea.setWrapStyleWord(true); + orthologLabel.setForeground(Color.BLUE); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); @@ -191,29 +189,21 @@ public class OrthologTable extends AbstractMatchTable Dimension dim; TableColumn tableCol; - if(column == getColumnIndex(ORGANISM_COL)) - { - organismTextArea.setText(text); - - tableCol = table.getColumnModel().getColumn(column); - organismTextArea.setSize(tableCol.getWidth(), table.getRowHeight(row)); - - dim = organismTextArea.getPreferredSize(); - minHeight = Math.max(minHeight, dim.height); - - c = organismTextArea; - } - else if(column == getColumnIndex(ORTHO_COL)) + if(column == getColumnIndex(ORTHO_COL)) { - orthologTextArea.setText(text); - - tableCol = table.getColumnModel().getColumn(column); - orthologTextArea.setSize(tableCol.getWidth(), table.getRowHeight(row)); - - dim = orthologTextArea.getPreferredSize(); - minHeight = Math.max(minHeight, dim.height); + orthologLabel.setText(text); + if(isSelected) + { + orthologLabel.setForeground(fgLinkColor); + orthologLabel.setBackground(table.getSelectionBackground()); + } + else + { + orthologLabel.setForeground(fgLinkColor); + orthologLabel.setBackground(UIManager.getColor("Button.background")); + } - c = orthologTextArea; + c = orthologLabel; } else if(column == getColumnIndex(DESCRIPTION_COL)) { -- GitLab