/* * * 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 java.util.StringTokenizer; import java.util.Vector; import javax.swing.border.*; import javax.swing.event.*; import javax.swing.text.html.*; import javax.swing.text.Document; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.BufferedReader; import java.io.StringReader; import java.io.IOException; import javax.swing.text.BadLocationException; import java.net.URL; public class Annotation extends JEditorPane implements HyperlinkListener { /** */ private static final long serialVersionUID = 1L; private int startRange; //private int endRange; /** busy cursor */ private Cursor cbusy = new Cursor(Cursor.WAIT_CURSOR); /** done cursor */ private Cursor cdone = new Cursor(Cursor.DEFAULT_CURSOR); /** desktop pane */ private JDesktopPane desktop = null; /** back option */ private Vector back = new Vector(); /** popup menu */ private JPopupMenu popup; /** known qualifiers */ private Vector qualifier = new Vector(); public Annotation(JDesktopPane desktop) { super(); this.desktop = desktop; setEditable(false); setContentType("text/html"); setFont(BigPane.font); addHyperlinkListener(this); } public Annotation(URL url) throws IOException { super(url); setEditable(false); addHyperlinkListener(this); // popup addMouseListener(new PopupListener()); popup = new JPopupMenu(); JMenuItem backMenu = new JMenuItem("Back"); popup.add(backMenu); backMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { goBack(); } }); back.add(url); } protected void setAnnotation(String text) { // setText("
"+text+""); // reportHTML(); // startRange = getDocument().getLength(); String line = null; // record qualifiers used try { BufferedReader buffRead = new BufferedReader(new StringReader(text)); while((line = buffRead.readLine()) != null) { int ind = line.indexOf("="); if(ind > -1) qualifier.add(line.substring(0,ind+1).toLowerCase()); } } catch(IOException ioe){} qualifier.add("/similarity="); qualifier.add("/gene="); qualifier.add("/GO_component="); qualifier.add("/product="); qualifier.add("/EC_number="); qualifier.add("/note="); text = getDatabaseHTML(text,"SWALL:"); text = getDatabaseHTML(text,"UniProt:"); text = getDatabaseHTML(text,"EMBL:"); setText(""+text+""); startRange = getDocument().getLength(); } protected void reportHTML() { try { String txt = ((HTMLDocument)getDocument()).getText(0,getDocument().getLength()); System.out.println("TXT:\n"+txt); System.out.println("\nHTML:\n"+getText()+"\n\n"); } catch(BadLocationException ble) { ble.printStackTrace(); } } protected String getFeatureText() { String txt = ""; try { txt = ((HTMLDocument)getDocument()).getText(0,getDocument().getLength()).trim(); StringBuffer buff = new StringBuffer(); StringTokenizer tok = new StringTokenizer(txt,"/"); int ntok = 0; while(tok.hasMoreTokens()) { String tokTxt = "/"+tok.nextToken().trim(); int ind = tokTxt.indexOf("="); if(ntok != 0 && ind > -1 && qualifier.contains(tokTxt.substring(0,ind+1))) buff.append("\n"+tokTxt); else buff.append(tokTxt); ntok++; } txt = buff.toString(); } catch(BadLocationException ble) { ble.printStackTrace(); } return txt; } protected void insert(String s, boolean ortholog) { s = getDatabaseHTML(s,"SWALL:"); s = getDatabaseHTML(s,"UniProt:"); s = getDatabaseHTML(s,"EMBL:"); s = getGeneDBHTML(s); // int ind = s.indexOf("/gene"); Document doc = getDocument(); int offset = doc.getLength(); if(ortholog) offset = startRange; insert(s,offset); setCaretPosition(doc.getLength()); // reportHTML(); } protected void insert(String s, int offset) { try { HTMLEditorKit edKit = (HTMLEditorKit)getEditorKit(); // ((HTMLDocument)getDocument()).insertString(offset,"\n",null); edKit.insertHTML((HTMLDocument)getDocument(),offset,"