📄 alignjframe.java
字号:
/***************************************************************** 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.** @author: Copyright (C) Tim Carver****************************************************************/package org.emboss.jemboss.editor;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.*;import java.io.File;import javax.swing.border.*;import java.net.URL;import org.emboss.jemboss.gui.form.TextFieldInt;import org.emboss.jemboss.gui.sequenceChooser.SequenceFilter;import org.emboss.jemboss.gui.filetree.FileEditorDisplay;import org.emboss.jemboss.gui.ScrollPanel;import org.emboss.jemboss.gui.Browser;/*** * Displays a grapical representation of a collection of* sequences.**/public class AlignJFrame extends JFrame{ private Vector graphicSequence; // Vector containing graphical seqs protected JScrollPane jspSequence; // Sequence scrollpane protected static GraphicSequenceCollection gsc; private static Matrix mat; private PrettyPlotJFrame ppj = null; protected static JTextField statusField = new JTextField(); private File sequenceFile = null; private Cursor cbusy = new Cursor(Cursor.WAIT_CURSOR); private Cursor cdone = new Cursor(Cursor.DEFAULT_CURSOR); protected JCheckBoxMenuItem residueColor; protected Hashtable currentColour; protected boolean useExitMenu = false; // whether to use 'Exit' or 'Close' protected JMenuBar menuBar; /** * * @param vseqs vector containing Sequence objects * */ public AlignJFrame(Vector vseqs) { this(); if(vseqs != null && vseqs.size() > 0) openMethod(vseqs); } /** * * @param seqFile sequence file * */ public AlignJFrame(File seqFile) { this(); SequenceReader sr = new SequenceReader(seqFile); sequenceFile = sr.getSequenceFile(); openMethod(sr.getSequenceVector()); setTitle("Jemboss Alignment Viewer :: "+ sequenceFile.getName()); } /** * * @param seqString formatted sequence string * @param name name of sequence set * */ public AlignJFrame(String seqString, String name) { this(); SequenceReader sr = new SequenceReader(seqString); sequenceFile = null; openMethod(sr.getSequenceVector()); setTitle("Jemboss Alignment Viewer :: "+name); } public AlignJFrame() { this(false); } /** * * @param useExitMenu true if an exit menu is to be displayed * otherwise a close menu is used * */ public AlignJFrame(boolean useExitMenu) { super("Jemboss Alignment Editor"); this.useExitMenu = useExitMenu; final Dimension dScreen = getToolkit().getScreenSize(); int interval = 10;// Vector seqs = new Vector(); mat = new Matrix("resources/resources.jar", "EBLOSUM62"); jspSequence = new JScrollPane(); jspSequence.getViewport().setBackground(Color.white); final JButton leftbutt = new JButton("Lock"); jspSequence.setCorner(JScrollPane.LOWER_LEFT_CORNER, leftbutt); leftbutt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(leftbutt.getText().equals("Lock")) { gsc.setSequenceLock(true); leftbutt.setText("Unlock"); } else { gsc.setSequenceLock(false); leftbutt.setText("Lock"); } } }); final JPanel mainPane = (JPanel)getContentPane();// set up a menu bar menuBar = new JMenuBar();// File menu JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F);// open sequence file final JMenuItem calculateCons = new JMenuItem("Consensus"); final JMenuItem calculatePlotCon = new JMenuItem("Consensus plot"); JMenuItem openSequence = new JMenuItem("Open..."); openSequence.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SequenceReader sr = new SequenceReader(); if(sr.isReading()) { sequenceFile = sr.getSequenceFile(); openMethod(sr.getSequenceVector()); calculateCons.setText("Calculate consensus"); calculatePlotCon.setText("Calculate consensus plot"); setTitle("Jemboss Alignment Viewer :: "+ sequenceFile.getName()); } } }); fileMenu.add(openSequence);// save JMenuItem saveAsMenu = new JMenuItem("Save As..."); saveAsMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new SequenceSaver(gsc.getSequenceCollection(),sequenceFile); } }); fileMenu.add(saveAsMenu); JMenuItem saveConsMenu = new JMenuItem("Save Consensus"); saveConsMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Vector v = new Vector(); v.add(gsc.getConsensusSequence()); new SequenceSaver(v); } }); fileMenu.add(saveConsMenu); // print JMenu printMenu = new JMenu("Print"); fileMenu.add(printMenu); JMenuItem print = new JMenuItem("Print Postscript..."); print.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new PrintAlignment(gsc); } }); printMenu.add(print);// JMenuItem printImage = new JMenuItem("Print Image Files (png/jpeg)..."); printImage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PrintAlignmentImage pai = new PrintAlignmentImage(gsc); pai.print(); } }); printMenu.add(printImage); JMenuItem printOneImage = new JMenuItem("Print to Single Image File..."); printOneImage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PrintAlignmentImage pai = new PrintAlignmentImage(gsc); String fsave = pai.showOptions(); if(fsave == null) return; pai.print(fsave,0.,0.,0.,0.); } }); printMenu.add(printOneImage);// print preview JMenu printPreviewMenu = new JMenu("Print Preview"); fileMenu.add(printPreviewMenu); JMenuItem printPreview = new JMenuItem("Multiple Pages..."); printPreview.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PrintAlignmentImage pai = new PrintAlignmentImage(gsc); pai.printPreview(); } }); printPreviewMenu.add(printPreview); JMenuItem printSinglePreview = new JMenuItem("Single Page..."); printSinglePreview.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PrintAlignmentImage pai = new PrintAlignmentImage(gsc); String type = pai.showPrintPreviewOptions(); pai.printSinglePagePreview(); } }); printPreviewMenu.add(printSinglePreview);// close fileMenu.add(new JSeparator()); if(!useExitMenu) { JMenuItem close = new JMenuItem("Close"); close.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_E, ActionEvent.CTRL_MASK)); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); fileMenu.add(close); } else // exit { JMenuItem fileMenuExit = new JMenuItem("Exit"); fileMenuExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.add(fileMenuExit); } menuBar.add(fileMenu); // Edit menu JMenu editMenu = new JMenu("Edit"); menuBar.add(editMenu); JMenuItem insertAnn = new JMenuItem("Insert Annotation Sequence"); editMenu.add(insertAnn); insertAnn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ScrollPanel pane = new ScrollPanel(new BorderLayout()); Box bacross = Box.createVerticalBox(); JRadioButton openFile = new JRadioButton("Read from File"); JRadioButton cut = new JRadioButton("Cut and Paste"); ButtonGroup group = new ButtonGroup(); group.add(openFile); group.add(cut); cut.setSelected(true); bacross.add(openFile); bacross.add(cut); pane.add(bacross,BorderLayout.CENTER); int selectedValue = JOptionPane.showConfirmDialog(null, pane, "Cut and Paste/Read from File", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if(selectedValue == JOptionPane.OK_OPTION) { SequenceReader sr = null; if(openFile.isSelected()) sr = new SequenceReader(); else { Paste pastePane = new Paste(); selectedValue = JOptionPane.showConfirmDialog(null, pastePane, "Cut and Paste", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if(selectedValue == JOptionPane.OK_OPTION) sr = new SequenceReader(pastePane.getSequence()); } if(sr != null && sr.isReading()) { sequenceFile = sr.getSequenceFile(); gsc.addAnnotationSequence(sr.getSequence(0)); Dimension dpane = gsc.getPanelSize(); gsc.setPreferredSize(dpane); gsc.setNamePanelWidth(gsc.getNameWidth()); jspSequence.setViewportView(gsc); } } } }); JMenuItem trimMenu = new JMenuItem("Trim Sequences"); editMenu.add(trimMenu); trimMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ScrollPanel pane = new ScrollPanel(new BorderLayout()); Box bacross = Box.createHorizontalBox(); TextFieldInt start = new TextFieldInt(); start.setValue(1); TextFieldInt end = new TextFieldInt(); end.setValue(gsc.getMaxSeqLength()); bacross.add(start); bacross.add(new JLabel(" start ")); bacross.add(end); bacross.add(new JLabel(" end")); pane.add(bacross,BorderLayout.CENTER); int selectedValue = JOptionPane.showConfirmDialog(null, pane, "Select Sequence Range to Use", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if(selectedValue == JOptionPane.OK_OPTION) { Vector vseq = gsc.getSequenceCollection(); Enumeration enumer = vseq.elements(); while(enumer.hasMoreElements()) { Sequence s = (Sequence)enumer.nextElement(); s.trim(start.getValue(),end.getValue()); } gsc.setMaxSeqLength(); gsc.repaint(); } } }); JMenuItem unlock = new JMenuItem("Unlock All Sequences"); editMenu.add(unlock); unlock.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gsc.setSequenceLock(false); } });// View menu JMenu viewMenu = new JMenu("View"); viewMenu.setMnemonic(KeyEvent.VK_V);// find pattern JMenuItem findMenu = new JMenuItem("Find pattern"); viewMenu.add(findMenu); final PatternJFrame patFrame = new PatternJFrame(); findMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Point pos = getLocationOnScreen(); pos.y = pos.y - patFrame.getHeight(); if(pos.y+patFrame.getHeight() > dScreen.getHeight()) pos.x = (int)(dScreen.getWidth()-patFrame.getHeight()); patFrame.setLocation(pos); patFrame.setGraphic(gsc); patFrame.setVisible(true); patFrame.toFront(); } }); viewMenu.add(new JSeparator());// matrix display JMenuItem showMatrix = new JMenuItem("Matrix Display"); viewMenu.add(showMatrix); final MatrixJFrame matFrame = new MatrixJFrame(mat,statusField, this); showMatrix.addActionListener(new ActionListener() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -