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
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,11 @@ import javax.swing.table.DefaultTableModel; ...@@ -48,7 +48,11 @@ import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn; 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.io.QualifierVector;
import uk.ac.sanger.artemis.util.DatabaseDocument;
abstract class AbstractMatchTable abstract class AbstractMatchTable
{ {
...@@ -212,12 +216,11 @@ abstract class AbstractMatchTable ...@@ -212,12 +216,11 @@ abstract class AbstractMatchTable
{ {
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
fireEditingStopped(); fireEditingStopped();
} }
}); });
} }
public Component getTableCellEditorComponent(JTable table, Object value, public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) boolean isSelected, int row, int column)
{ {
...@@ -264,6 +267,119 @@ abstract class AbstractMatchTable ...@@ -264,6 +267,119 @@ abstract class AbstractMatchTable
catch(ArrayIndexOutOfBoundsException e){} 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 //http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 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; package uk.ac.sanger.artemis.components.genebuilder.ortholog;
...@@ -151,7 +151,11 @@ public class MatchPanel extends JPanel ...@@ -151,7 +151,11 @@ public class MatchPanel extends JPanel
//{ //{
if(hide_show_ortho == null) if(hide_show_ortho == null)
hide_show_ortho = new JButton("-"); 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); addHideShowButton(orthologTable.getTable(), hide_show_ortho);
xBox.add(hide_show_ortho); xBox.add(hide_show_ortho);
editableComponents.add(orthologTable); editableComponents.add(orthologTable);
......
...@@ -43,17 +43,18 @@ import javax.swing.table.TableModel; ...@@ -43,17 +43,18 @@ import javax.swing.table.TableModel;
import uk.ac.sanger.artemis.io.Qualifier; import uk.ac.sanger.artemis.io.Qualifier;
import uk.ac.sanger.artemis.io.QualifierVector; import uk.ac.sanger.artemis.io.QualifierVector;
import uk.ac.sanger.artemis.util.DatabaseDocument;
public class OrthologTable extends AbstractMatchTable public class OrthologTable extends AbstractMatchTable
{ {
private int NUMBER_COLUMNS = 4; private int NUMBER_COLUMNS = 3;
private Vector rowData = new Vector(); private Vector rowData = new Vector();
private Vector tableData = new Vector(NUMBER_COLUMNS); private Vector tableData = new Vector(NUMBER_COLUMNS);
private JTable orthologTable; private JTable orthologTable;
private JButton infoLevelButton = new JButton("Details"); private JButton infoLevelButton = new JButton("Details");
private Qualifier origQualifier; private Qualifier origQualifier;
private boolean isChanged = false; private boolean isChanged = false;
// //
// column headings // column headings
final static String ORGANISM_COL = "Organism"; final static String ORGANISM_COL = "Organism";
...@@ -66,32 +67,29 @@ public class OrthologTable extends AbstractMatchTable ...@@ -66,32 +67,29 @@ public class OrthologTable extends AbstractMatchTable
* @param similarity * @param similarity
* @param similarityString * @param similarityString
*/ */
protected OrthologTable(final Qualifier origQualifier) protected OrthologTable(final DatabaseDocument doc,
final Qualifier origQualifier)
{ {
this.origQualifier = origQualifier; this.origQualifier = origQualifier;
infoLevelButton.setOpaque(false); infoLevelButton.setOpaque(false);
tableData.setSize(NUMBER_COLUMNS); tableData.setSize(NUMBER_COLUMNS);
tableData.setElementAt(ORGANISM_COL,0); tableData.setElementAt(ORTHO_COL,0);
tableData.setElementAt(ORTHO_COL,1); tableData.setElementAt(DESCRIPTION_COL,1);
tableData.setElementAt(DESCRIPTION_COL,2); tableData.setElementAt(REMOVE_BUTTON_COL,2);
tableData.setElementAt(REMOVE_BUTTON_COL,3);
// add row data // add row data
Vector thisRowData = new Vector(); Vector thisRowData = new Vector();
thisRowData.add("organism"); thisRowData.add("Bpseudomallei:BPSL0003");
thisRowData.add("blah");
thisRowData.add("blah blah"); thisRowData.add("blah blah");
rowData.add(thisRowData); rowData.add(thisRowData);
Vector thisRowData2 = new Vector(); Vector thisRowData2 = new Vector();
thisRowData2.add("organism2"); thisRowData2.add("Bpseudomallei:BPSL2915");
thisRowData2.add("blah2");
thisRowData2.add("blah blah2"); thisRowData2.add("blah blah2");
rowData.add(thisRowData2); rowData.add(thisRowData2);
Vector thisRowData3 = new Vector(); Vector thisRowData3 = new Vector();
thisRowData3.add("organism3"); thisRowData3.add("schema:id");
thisRowData3.add("blah3");
thisRowData3.add("blah blah3"); thisRowData3.add("blah blah3");
rowData.add(thisRowData3); rowData.add(thisRowData3);
...@@ -124,6 +122,11 @@ public class OrthologTable extends AbstractMatchTable ...@@ -124,6 +122,11 @@ public class OrthologTable extends AbstractMatchTable
col = orthologTable.getColumn(REMOVE_BUTTON_COL); col = orthologTable.getColumn(REMOVE_BUTTON_COL);
col.setCellEditor(new ButtonEditor(new JCheckBox(), col.setCellEditor(new ButtonEditor(new JCheckBox(),
(DefaultTableModel)orthologTable.getModel())); (DefaultTableModel)orthologTable.getModel()));
// orthologue link
col = orthologTable.getColumn(ORTHO_COL);
col.setCellEditor(new LinkEditor(new JCheckBox(),
(DefaultTableModel)orthologTable.getModel(), doc));
} }
protected boolean isQualifierChanged() protected boolean isQualifierChanged()
...@@ -148,20 +151,15 @@ public class OrthologTable extends AbstractMatchTable ...@@ -148,20 +151,15 @@ public class OrthologTable extends AbstractMatchTable
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int minHeight = -1; private int minHeight = -1;
private final JTextArea orthologTextArea = new JTextArea(); private final JLabel orthologLabel = new JLabel();
private final JTextArea organismTextArea = new JTextArea();
private final JTextArea descriptionTextArea = new JTextArea(); private final JTextArea descriptionTextArea = new JTextArea();
private final JLabel buttRemove = new JLabel("X"); private final JLabel buttRemove = new JLabel("X");
private Color fgColor = new Color(139,35,35); private Color fgColor = new Color(139,35,35);
private Color fgLinkColor = Color.BLUE;
public OrthologRenderer() public OrthologRenderer()
{ {
orthologLabel.setForeground(Color.BLUE);
organismTextArea.setLineWrap(true);
organismTextArea.setWrapStyleWord(true);
orthologTextArea.setLineWrap(true);
orthologTextArea.setWrapStyleWord(true);
descriptionTextArea.setLineWrap(true); descriptionTextArea.setLineWrap(true);
descriptionTextArea.setWrapStyleWord(true); descriptionTextArea.setWrapStyleWord(true);
...@@ -191,29 +189,21 @@ public class OrthologTable extends AbstractMatchTable ...@@ -191,29 +189,21 @@ public class OrthologTable extends AbstractMatchTable
Dimension dim; Dimension dim;
TableColumn tableCol; 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;
}
else if(column == getColumnIndex(ORTHO_COL))
{ {
orthologTextArea.setText(text); orthologLabel.setText(text);
if(isSelected)
tableCol = table.getColumnModel().getColumn(column); {
orthologTextArea.setSize(tableCol.getWidth(), table.getRowHeight(row)); orthologLabel.setForeground(fgLinkColor);
orthologLabel.setBackground(table.getSelectionBackground());
dim = orthologTextArea.getPreferredSize(); }
minHeight = Math.max(minHeight, dim.height); else
{
orthologLabel.setForeground(fgLinkColor);
orthologLabel.setBackground(UIManager.getColor("Button.background"));
}
c = orthologTextArea; c = orthologLabel;
} }
else if(column == getColumnIndex(DESCRIPTION_COL)) else if(column == getColumnIndex(DESCRIPTION_COL))
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment