Newer
Older
/*
*
* created: Wed Aug 3 2004
*
* This file is part of Artemis
*
* Copyright(C) 2000 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or(at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package uk.ac.sanger.artemis.editor;
import javax.swing.*;
import java.awt.*;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.StringTokenizer;
import java.util.Enumeration;
import java.io.BufferedReader;
import java.io.StringReader;
import java.io.IOException;
public class DataViewInternalFrame extends JInternalFrame
{
private JTabbedPane tabPane = new JTabbedPane();
final JScrollPane scrollEvidence,
int wid, int hgt, String qualifier_txt)
{
super("Document " + dataFile[0],
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
// graphical evidence display
JInternalFrame evidence = new JInternalFrame("Evidence", true,
true, true, true);
JPanel evidencePanel = (JPanel)evidence.getContentPane();
evidenceBox = Box.createVerticalBox();
//
//ensure results file exists
File fdata = new File((String)dataFile[i]);
if(!fdata.exists())
{
fdata = new File((String)dataFile[i]+".gz");
if(!fdata.exists())
{
JOptionPane.showMessageDialog(desktop, "Results file: \n"+
dataFile[i] + "\ndoes not exist!",
"File Not Found",
JOptionPane.WARNING_MESSAGE);
continue;
}
}
String tabName = (String)dataFile[i];
int ind = tabName.lastIndexOf("/");
if(ind > -1)
{
String go = "";
if(tabName.indexOf("blastp+go") > -1)
go = ":: GO :: ";
tabName = go + tabName.substring(ind+1);
}
if(qualifier_txt.indexOf("/"+fastaPane.getFormat()+"_file=\"") == -1)
{
if(i > 0)
annFormat.append("\n<br>");
annFormat.append("/"+fastaPane.getFormat()+"_file=\""+
dataFile[i]+"\"");
}
final JScrollPane dbviewScroll = new JScrollPane();
final DBViewer dbview = new DBViewer(fastaPane,dbviewScroll);
final Dimension d = new Dimension((int)dbviewScroll.getPreferredSize().getWidth(),
hgt/3);
final Box xBox = Box.createHorizontalBox();
final MouseOverButton hide = new MouseOverButton("X");
hide.setForeground(Color.blue);
hide.setBackground(Color.white);
hide.setFont(BigPane.font);
hide.setMargin(new Insets(0,0,0,0));
hide.setBorderPainted(false);
hide.setActionCommand("HIDE");
final Box bacross = Box.createHorizontalBox();
bacross.add(dbviewScroll);
hide.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(hide.getActionCommand().equals("HIDE"))
{
bacross.remove(dbviewScroll);
hide.setText("+");
scrollEvidence.setViewportView(evidenceBox);
hide.setActionCommand("SHOW");
}
else
{
bacross.remove(yBox);
dbviewScroll.setColumnHeaderView(yBox);
bacross.add(dbviewScroll);
hide.setText("X");
scrollEvidence.setViewportView(evidenceBox);
hide.setActionCommand("HIDE");
}
}
});
xBox.add(hide);
JLabel tabLabel = new JLabel(fastaPane.getFormat()+" "+tabName);
tabLabel.setFont(BigPane.font);
tabLabel.setOpaque(true);
xBox.add(tabLabel);
xBox.add(Box.createHorizontalGlue());
yBox.add(xBox);
yBox.add(dbview.getRuler());
ActiveJSplitPane split = new ActiveJSplitPane(JSplitPane.VERTICAL_SPLIT,
fastaPane,dataPane);
split.setLabel(tabLabel);
// add tab pane listener
tabPane.addChangeListener(new TabChangeListener());
JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
annotationScroll,tabPane);
evidence.setVisible(true);
desktop.add(evidence);
}
protected Box getEvidenceBox()
{
return evidenceBox;
protected String getFeatureText()
{
return ann.getFeatureText();
}
ActiveJSplitPane split = (ActiveJSplitPane)tabPane.getSelectedComponent();
Component comps[] = split.getComponents();
for(int i=0; i<comps.length;i++)
{
protected void stopGetz()
{
Enumeration fastaEnum = fastaCollection.elements();
while(fastaEnum.hasMoreElements())
((FastaTextPane)fastaEnum.nextElement()).stopGetz();
}
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/**
*
* Delete note field in for all similar hits.
*
*/
protected void deleteNote()
{
ann.deleteNote();
}
/**
*
* Add a note field in for all similar hits.
*
*/
protected void updateNote()
{
StringReader in = new StringReader(getFeatureText());
BufferedReader buff = new BufferedReader(in);
String line = null;
StringBuffer note = null;
try
{
while((line = buff.readLine()) != null)
{
if(line.startsWith("/similarity="))
{
if(note == null)
StringTokenizer tok = new StringTokenizer(line,";");
String type = tok.nextToken();
int ind1 = type.indexOf("\"");
type = type.substring(ind1+1);
String id = tok.nextToken();
String next = tok.nextToken().trim();
if(next.endsWith("."))
next = next.substring(0,next.length()-1);
note.append(next);
if(!length.startsWith("length"))
note.append(" "+length.toLowerCase());
note.append(" "+id);
while(!length.startsWith("length"))
length = tok.nextToken().trim();
note.append(" ("+length+") ");
note.append(type+" scores: ");
String pid = tok.nextToken().trim(); // percent id
if(pid.endsWith("%")) // fasta
{
ind1 = pid.indexOf(" ");
pid = pid.substring(ind1+1);
tok.nextToken(); // ungapped id
String eval = tok.nextToken().trim();
String len = tok.nextToken().trim();
while(!len.endsWith("aa overlap"))
len = tok.nextToken().trim();
note.append(eval);
note.append(", "+pid+" id in ");
note.append(len);
}
else // blastp
note.append(pid);
}
}
}
catch(IOException ioe){}
if(note != null)
note.append("\"");
else
return;
ann.insert(note.toString(),true);
// System.out.println(note.toString());
// Enumeration enumHits = hits.elements();
// while(enumHits.hasMoreElements())
// {
// String id = (String)enumHits.nextElement();
// System.out.println(id);
// findHitInfo(String
// }
return;
}
private String htmlBreaks(String t)
{
int ind = 0;
while((ind = t.indexOf("\n",ind+5)) > -1)
t = t.substring(0,ind) + "<br>" +
t.substring(ind);
return t;
}
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
public class TabChangeListener implements ChangeListener
{
ActiveJSplitPane lastSelected = (ActiveJSplitPane)tabPane.getSelectedComponent();
public void stateChanged(ChangeEvent e)
{
ActiveJSplitPane split = (ActiveJSplitPane)tabPane.getSelectedComponent();
lastSelected.setActive(false);
split.setActive(true);
lastSelected = split;
}
}
public class ActiveJSplitPane extends JSplitPane
{
private JLabel tabLabel;
private Color bg;
public ActiveJSplitPane(int newOrientation,
Component newLeftComponent,
Component newRightComponent)
{
super(newOrientation,newLeftComponent,newRightComponent);
}
public void setLabel(JLabel tabLabel)
{
this.tabLabel = tabLabel;
this.bg = tabLabel.getBackground();
}
public void setActive(boolean active)
{
if(active)
tabLabel.setBackground(Color.yellow);
else
tabLabel.setBackground(bg);
}
}