Skip to content
Snippets Groups Projects
Commit 3aa725b6 authored by tjc's avatar tjc
Browse files

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
parent 1cf3bde3
Branches
Tags
No related merge requests found
......@@ -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
{
......@@ -213,7 +217,6 @@ abstract class AbstractMatchTable
public void actionPerformed(ActionEvent e)
{
fireEditingStopped();
}
});
}
......@@ -265,6 +268,119 @@ abstract class AbstractMatchTable
}
}
/**
*
*/
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
//
......
......@@ -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);
......
......@@ -43,10 +43,11 @@ 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;
......@@ -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))
if(column == getColumnIndex(ORTHO_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;
orthologLabel.setText(text);
if(isSelected)
{
orthologLabel.setForeground(fgLinkColor);
orthologLabel.setBackground(table.getSelectionBackground());
}
else if(column == getColumnIndex(ORTHO_COL))
else
{
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.setForeground(fgLinkColor);
orthologLabel.setBackground(UIManager.getColor("Button.background"));
}
c = orthologTextArea;
c = orthologLabel;
}
else if(column == getColumnIndex(DESCRIPTION_COL))
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment