📄 browser.java
字号:
/********************************************************************** 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 javax.swing.*;import javax.swing.event.*;import javax.swing.tree.*;import java.awt.*;import java.awt.geom.*;import java.awt.event.*;import java.net.*;import java.io.*;import java.util.Vector;import javax.swing.border.*;import org.emboss.jemboss.JembossParams;/**** Jemboss web browser**/public class Browser extends JFrame implements HyperlinkListener, ActionListener{ /** status field */ private JTextField statusField; /** URL cache combo field */ private MemoryComboBox urlField; /** HTML pane */ private JEditorPane htmlPane; /** initial URL */ private String initialURL; /** busy cursor */ private Cursor cbusy = new Cursor(Cursor.WAIT_CURSOR); /** done cursor */ private Cursor cdone = new Cursor(Cursor.DEFAULT_CURSOR); /** Help topics */ private String topics[] = { "Home", "About", "User Guide", "File Manager", "Results Manager", "Sequence List", "Alignment Editor"}; private String embossTopics[] = { "Home", "Apps"}; /** JSplitPane sp */ private JSplitPane sp; /** Back menu option */ private JMenuItem backMenu; /** Back button option */ private JButton backBt; /** Forward menu option */ private JMenuItem fwdMenu; /** Forward button option */ private JButton fwdBt; /** * * @param initialURL initial URL * @param name browser frame title * @param mysettings jemboss settings * */ public Browser(String initialURL, String name, JembossParams mysettings) throws IOException { this(initialURL,name,false,"",mysettings); } /** * * @param initialURL initial URL * @param name browser frame title * @param ltext true if html as string past to web browser * @param text html as string * @param mysettings jemboss settings * */ public Browser(String initialURL, String name, boolean ltext, String text, JembossParams mysettings) throws IOException { super(name); this.initialURL = initialURL; if(mysettings.isBrowserProxy()) { System.setProperty("http.proxyHost",mysettings.getBrowserProxyHost()); System.setProperty("http.proxyPort", Integer.toString( mysettings.getBrowserProxyPort())); System.setProperty("proxyHost",mysettings.getBrowserProxyHost()); System.setProperty("proxyPort", Integer.toString( mysettings.getBrowserProxyPort())); } if(ltext) { htmlPane = new JEditorPane(); if( (text.indexOf("<html>") > -1) || (text.indexOf("<HTML>") > -1) ) htmlPane.setContentType("text/html"); htmlPane.setText(text); htmlPane.addHyperlinkListener(this); setBrowserSize(); Vector urlCache = new Vector(); urlCache.add(name+".html"); setUpJMenuBar(urlCache); addToScrollPane(); setVisible(true); } else { URL pageURL = new URL(initialURL); setURL(pageURL,initialURL); } } /** * * @param urlName URL to display * @param initialURL initial URL * */ public Browser(URL urlName, String initialURL) throws IOException { super(initialURL); this.initialURL = initialURL; setURL(urlName,initialURL); } /** * * Set the URL in the browser * @param url URL to display * @param name URL name * */ public void setURL(URL url, String name) { try { htmlPane = new JEditorPane(url); htmlPane.addHyperlinkListener(this); Vector urlCache = new Vector(); urlCache.add(url); setBrowserSize(); setUpJMenuBar(urlCache); setTitle(name); addToScrollPane(); setVisible(true); } catch(IOException ioe) { JOptionPane.showMessageDialog(null, "Cannot Load URL\n"+name, "Error", JOptionPane.ERROR_MESSAGE); } } /** * * Method to create the frames menu and tool bar. * @param urlCache URL cache * */ private void setUpJMenuBar(Vector urlCache) { JMenuBar menuBar = new JMenuBar(); JToolBar toolBarURL = new JToolBar(); JToolBar toolBarIcon = new JToolBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu); // back backMenu = new JMenuItem("Back"); backMenu.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_B, ActionEvent.CTRL_MASK)); backMenu.setActionCommand("BACK"); backMenu.addActionListener(this); fileMenu.add(backMenu); backMenu.setEnabled(false); fwdMenu = new JMenuItem("Forward"); fwdMenu.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_F, ActionEvent.CTRL_MASK)); fwdMenu.setActionCommand("FWD"); fwdMenu.addActionListener(this); fileMenu.add(fwdMenu); // close fileMenu.addSeparator(); JMenuItem closeMenu = new JMenuItem("Close"); closeMenu.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_E, ActionEvent.CTRL_MASK)); closeMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); fileMenu.add(closeMenu); // view JMenu viewMenu = new JMenu("View"); viewMenu.setMnemonic(KeyEvent.VK_V); menuBar.add(viewMenu); JCheckBoxMenuItem sideTopics = new JCheckBoxMenuItem( "Display help topics"); sideTopics.setSelected(true); sideTopics.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_L, ActionEvent.CTRL_MASK)); sideTopics.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(sp.getDividerLocation() > 5) sp.setDividerLocation(0); else sp.setDividerLocation(100); } }); viewMenu.add(sideTopics); // jemboss logo button ClassLoader cl = this.getClass().getClassLoader(); ImageIcon jem = new ImageIcon(cl.getResource( "images/Jemboss_logo_small.gif")); JIconButton jembossButton = new JIconButton(jem); jembossButton.addActionListener(this); jembossButton.setActionCommand("JEMBOSS"); // url field JLabel urlLabel = new JLabel("URL:"); urlField = new MemoryComboBox(urlCache); urlField.addActionListener(this); int urlFieldHeight = (int)urlField.getPreferredSize().getHeight();// Icon tool bar // Back JButton backBt = new JButton() { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setColor(new Color(0,128,0)); float loc1[][] = { {4,12}, {14,22}, {14,16}, {18,16}, {18,12} }; g2.fill(Browser.makeShape(loc1)); g2.setColor(Color.green); float loc2[][] = { {4,12}, {14,2}, {14,8}, {18,8}, {18,12} }; g2.fill(Browser.makeShape(loc2)); if(!isEnabled()) { g2.setColor(Color.gray); float loc3[][] = { {5,12}, {14,21}, {14,15}, {18,15}, {18,12} }; g2.fill(Browser.makeShape(loc3)); g2.setColor(Color.lightGray); float loc4[][] = { {5,12}, {14,3}, {14,9}, {18,9}, {18,12} }; g2.fill(Browser.makeShape(loc4)); } setSize(22,24); } }; Dimension dBut = new Dimension(22,24); backBt.setPreferredSize(dBut); backBt.setMaximumSize(dBut); backBt.setPreferredSize(new Dimension(15,15)); backBt.setActionCommand("BACK"); backBt.addActionListener(this); backBt.setEnabled(false); // Forward JButton fwdBt = new JButton() { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setColor(new Color(0,128,0)); float loc1[][] = { {4,12}, {4,16}, {8,16}, {8,22}, {18,12} }; g2.fill(Browser.makeShape(loc1)); g2.setColor(Color.green); float loc2[][] = { {4,12}, {4,8}, {8,8}, {8,2}, {18,12} }; g2.fill(Browser.makeShape(loc2)); if(!isEnabled()) { g2.setColor(Color.gray); float loc3[][] = { {4,12}, {4,15}, {8,15}, {8,21}, {17,12} }; g2.fill(Browser.makeShape(loc3)); g2.setColor(Color.lightGray); float loc4[][] = { {4,12}, {4,7}, {8,7}, {8,3}, {17,12} }; g2.fill(Browser.makeShape(loc4)); } setSize(22,24); } }; fwdBt.setPreferredSize(dBut); fwdBt.setMaximumSize(dBut); fwdBt.setActionCommand("FWD"); fwdBt.addActionListener(this); fwdBt.setEnabled(false); toolBarIcon.add(backBt); toolBarIcon.add(fwdBt); toolBarIcon.add(jembossButton); toolBarURL.add(urlLabel); toolBarURL.add(urlField); setJMenuBar(menuBar); JPanel toolBars = new JPanel(new BorderLayout()); toolBars.add(toolBarIcon, BorderLayout.NORTH); toolBars.add(toolBarURL, BorderLayout.SOUTH); getContentPane().add(toolBars, BorderLayout.NORTH); int urlFieldWidth = (int)toolBarURL.getPreferredSize().getWidth(); Dimension d = new Dimension(urlFieldWidth,urlFieldHeight); urlField.setMaximumSize(d); int iconBarWidth = (int)toolBarIcon.getPreferredSize().getWidth(); int iconBarHeight = jem.getIconHeight(); d = new Dimension(iconBarWidth,iconBarHeight); toolBarIcon.setPreferredSize(d); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -