⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resultsmenubar.java

📁 emboss的linux版本的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************  This library is free software; you can redistribute it and/or*  modify it under the terms of the GNU Library General Public*  License as published by the Free Software Foundation; either*  version 2 of the License, or (at your option) any later version.* *  This library 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*  Library General Public License for more details.* *  You should have received a copy of the GNU Library General Public*  License along with this library; 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.gui;import java.util.Hashtable;import java.util.Vector;import java.awt.*;import javax.swing.*;import javax.swing.event.*;import java.awt.event.*;import java.io.File;import javax.swing.border.*;import javax.swing.undo.UndoManager;import javax.swing.undo.CannotRedoException;import javax.swing.text.JTextComponent;import org.emboss.jemboss.soap.PrivateRequest;import org.emboss.jemboss.soap.JembossSoapException;import org.emboss.jemboss.gui.sequenceChooser.SequenceFilter;import org.emboss.jemboss.gui.filetree.*;import org.emboss.jemboss.gui.AdvancedOptions;import org.emboss.jemboss.JembossParams;import org.emboss.jemboss.server.JembossServer;/**** Sets up a results menu bar with save and close* */public class ResultsMenuBar extends JMenuBar{  /** menu to save to local file   */  private JMenuItem saveToLocalFile;  /** menu to save to remote file  */  private JMenuItem saveToRemoteFile;  /** frame containing the results */  private JFrame frame;  /** tool bar */  private JToolBar toolBar = new JToolBar();  /** undo menu item */  private JMenuItem undo = new JMenuItem("Undo");  /** redo menu item */  private JMenuItem redo = new JMenuItem("Redo");  /** undo manager   */  private UndoManager undoManager = new UndoManager();  /**  *  * Sets up a results menu bar with save and close  * @param frame 	frame containing the results  * @param rtb		tabbed pane for results   * @param hashOut	output/result files  * @param mysettings 	jemboss properties  *  */   public ResultsMenuBar(final JFrame frame, final JTabbedPane rtb,                        final Hashtable hashOut, JembossParams mysettings)  {    this(frame,rtb,hashOut,null,null,mysettings);   }  /**  *  * Sets up a results menu bar with save and close  * @param frame        frame containing the results  * @param rtb          tabbed pane for results  * @param hashOut      output/result files  * @param hashIn	input files  *  */  public ResultsMenuBar(final JFrame frame, final JTabbedPane rtb,                        final Hashtable hashOut, final Hashtable hashIn)  {    this(frame,rtb,hashOut,hashIn,null,null);  }  /**  *  * Adds action listener to save contents of a JTextPane. This  * allows editing of the area to be saved.  * @param frame 	frame containing the results  * @param fed		text area to add listener to  * @param mysettings	jemboss properties  *  */  public ResultsMenuBar(final JFrame frame, final FileEditorDisplay fed,                         final JembossParams mysettings)  {    setResultsMenuBar(frame,false);    saveToLocalFile.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        FileSaving fsave = new FileSaving(fed, fed.getPNGContent(), mysettings);        if(fsave.writeOK())        {          String fileSelected = fsave.getFileName();          String pathSelected = fsave.getPath();          try          {            org.emboss.jemboss.Jemboss.tree.addObject(fileSelected,pathSelected,null);          }          catch(NullPointerException npe){}          DragTree ltree = LocalAndRemoteFileTreeFrame.getLocalDragTree();          if(ltree!=null)            ltree.addObject(fileSelected,pathSelected,null);        }      }    });    // undo - redo    fed.getDocument().addUndoableEditListener(new UndoableEditListener()     {      public void undoableEditHappened(UndoableEditEvent e)       {        undoManager.addEdit(e.getEdit());        updateMenu();      }    });    undo.addActionListener(new ActionListener()     {      public void actionPerformed(ActionEvent e)       {        try { undoManager.undo(); }        catch (CannotRedoException cre) { cre.printStackTrace(); }        updateMenu();      }    });    redo.addActionListener(new ActionListener()     {      public void actionPerformed(ActionEvent e)       {        try { undoManager.redo(); }        catch (CannotRedoException cre) { cre.printStackTrace(); }        updateMenu();      }    });    //Colour selection    JMenu colourMenu   = new JMenu("Colour");    colourMenu.setMnemonic(KeyEvent.VK_L);    ColorMenu cm = new ColorMenu("Text");    cm.setColor(fed.getForeground());    cm.setMnemonic('t');    ActionListener lst = new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        ColorMenu m = (ColorMenu)e.getSource();        fed.setForeground(m.getColor());      }    };    cm.addActionListener(lst);    colourMenu.add(cm);    cm = new ColorMenu("Background");    cm.setColor(fed.getBackground());    cm.setMnemonic('b');    lst = new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        ColorMenu m = (ColorMenu)e.getSource();        fed.setBackground(m.getColor());      }    };    cm.addActionListener(lst);    colourMenu.add(cm);    add(colourMenu);    //Text - sequence display option    ButtonGroup group = new ButtonGroup();    JMenu optionsMenu   = new JMenu("Options");    JRadioButtonMenuItem optionsMenuText = new JRadioButtonMenuItem("Text");    optionsMenu.add(optionsMenuText);    optionsMenuText.setSelected(true);    group.add(optionsMenuText);    JRadioButtonMenuItem optionsMenuSeq = new JRadioButtonMenuItem("Sequence");    optionsMenu.add(optionsMenuSeq);    group.add(optionsMenuSeq);    add(optionsMenu);    optionsMenuSeq.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        if(((JRadioButtonMenuItem)e.getSource()).isSelected())        {          String text = fed.getText();          fed.setText("");          fed.setText(text,"sequence");          fed.setCaretPosition(0);        }      }    });    optionsMenuText.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        if(((JRadioButtonMenuItem)e.getSource()).isSelected())        {          String text = fed.getText();          fed.setText("");          fed.setText(text,"regular");          fed.setCaretPosition(0);        }      }    });    add(optionsMenu);     //Font size selection    String sizes[] = {"10", "12", "14", "16", "18"};    final JComboBox fntSize = new JComboBox(sizes);    Font fnt = fed.getFont();    fntSize.setSelectedItem(Integer.toString(fnt.getSize()));    fntSize.setPreferredSize(fntSize.getMinimumSize());    fntSize.setMaximumSize(fntSize.getMinimumSize());    fntSize.setEditable(true);    toolBar.add(fntSize);    fntSize.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        Font fnt = fed.getFont();        try        {          String fsize = (String)fntSize.getSelectedItem();          if(fsize.indexOf(".") > -1)            fsize = fsize.substring(0,fsize.indexOf("."));          fnt = new Font(fnt.getFontName(),fnt.getStyle(),                         Integer.parseInt(fsize));          fed.setFont(fnt);        } catch(NumberFormatException nfe){}      }    });    //Font style    String styles[] = {"Plain","Bold","Italic"};    final JComboBox cbFonts = new JComboBox(styles);    cbFonts.setMaximumSize(cbFonts.getPreferredSize());    cbFonts.setToolTipText("Available styles");    cbFonts.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        int index = cbFonts.getSelectedIndex();        if (index < 0)          return;        Font fnt = fed.getFont();        if(index == 0)          fnt = fnt.deriveFont(Font.PLAIN);        else if(index == 1)          fnt = fnt.deriveFont(Font.BOLD);        else          fnt = fnt.deriveFont(Font.ITALIC);        fed.setFont(fnt);      }    });    toolBar.add(cbFonts); }  /**  *  * Adds action listener to save contents of contents of a  * tabbed pane. Allows saving to files of text and png files.  * @param frame 	frame containing the results  * @param rtb 		tab pane containing results  * @param hashIn 	containing results  * @param project	project name  * @param mysettings	jemboss properties  *  */  public ResultsMenuBar(final JFrame frame, final JTabbedPane rtb,                        final Hashtable hashOut, final Hashtable hashIn,                        final String project, final JembossParams mysettings)  {    boolean addRemoteSaveMenu = false;    if(project != null)      addRemoteSaveMenu = true;    setResultsMenuBar(frame, addRemoteSaveMenu);    saveToLocalFile.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        String fileSelected = "";        String cwd = "";        SecurityManager sm = System.getSecurityManager();        System.setSecurityManager(null);        JFileChooser fc = new JFileChooser(mysettings.getUserHome());        System.setSecurityManager(sm);        fc.addChoosableFileFilter(new SequenceFilter());        int returnVal = fc.showSaveDialog(fc);        if (returnVal == JFileChooser.APPROVE_OPTION)        {          File files = fc.getSelectedFile();          cwd = (fc.getCurrentDirectory()).getAbsolutePath();          fileSelected = files.getName();          frame.setCursor(new Cursor(Cursor.WAIT_CURSOR));//        save results          String tabTitle = rtb.getTitleAt(rtb.getSelectedIndex());          JTextComponent jtc = getJTextComponentAt(rtb,rtb.getSelectedIndex());          if(jtc != null)    // text save          {            fileSave(cwd,fileSelected,jtc.getText());          }          else               // image icon save          {            if(hashOut.containsKey(tabTitle))              fileSave(cwd,fileSelected,tabTitle,hashOut);            else if(hashIn != null)            {              if(hashIn.containsKey(tabTitle))                fileSave(cwd,fileSelected,tabTitle,hashIn);            }          }          frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));        }      }    });// undo - redo    for(int i =0; i<rtb.getTabCount(); i++)    {      JTextComponent jtc = getJTextComponentAt(rtb,i);      if(jtc != null)        jtc.getDocument().addUndoableEditListener(new UndoableEditListener()        {          public void undoableEditHappened(UndoableEditEvent e)          {            undoManager.addEdit(e.getEdit());            updateMenu();          }        });    }    undo.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        try { undoManager.undo(); }        catch (CannotRedoException cre) { cre.printStackTrace(); }        updateMenu();      }    });    redo.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        try { undoManager.redo(); }        catch (CannotRedoException cre) { cre.printStackTrace(); }        updateMenu();      }    });    //Colour selection    JMenu colourMenu   = new JMenu("Colour");    colourMenu.setMnemonic(KeyEvent.VK_L);    ColorMenu cm = new ColorMenu("Text");    cm.setMnemonic('t');    ActionListener lst = new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        ColorMenu m = (ColorMenu)e.getSource();        JTextPane jtp = getSelectedJTextPane(rtb);        if(jtp != null)          jtp.setForeground(m.getColor());      }    };    cm.addActionListener(lst);    colourMenu.add(cm);     cm = new ColorMenu("Background");    cm.setMnemonic('b');    lst = new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        ColorMenu m = (ColorMenu)e.getSource();        JTextPane jtp = getSelectedJTextPane(rtb);        if(jtp != null)          jtp.setBackground(m.getColor());      }    };    cm.addActionListener(lst);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -