001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 * Created on Oct 6, 2009 021 * Author: Andreas Prlic 022 * 023 */ 024 025package org.biojava.nbio.structure.align.gui; 026 027import org.biojava.nbio.structure.align.util.ResourceManager; 028import org.biojava.nbio.structure.align.webstart.BrowserOpener; 029 030import javax.swing.*; 031import javax.swing.event.HyperlinkEvent; 032import javax.swing.event.HyperlinkListener; 033import java.awt.*; 034import java.awt.event.ActionEvent; 035import java.awt.event.ActionListener; 036 037public class HelpDialog { 038 Box vBox; 039 040 public void showDialog(){ 041 042 JDialog dialog = new JDialog(); 043 044 dialog.setSize(new Dimension(500,600)); 045 046 ResourceManager mgr = ResourceManager.getResourceManager("ce"); 047 048 String msg = mgr.getString("ce.help"); 049 050 JEditorPane txt = new JEditorPane("text/html", msg); 051 txt.setEditable(false); 052 053 JScrollPane scroll = new JScrollPane(txt); 054 scroll.setSize(new Dimension(300,500)); 055 vBox= Box.createVerticalBox(); 056 vBox.add(scroll); 057 058 txt.addHyperlinkListener(new HyperlinkListener(){ 059 060 @Override 061 public void hyperlinkUpdate(HyperlinkEvent e) { 062 063 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { 064 String href = e.getDescription(); 065 BrowserOpener.showDocument(href); 066 } 067 if ( e.getEventType() == HyperlinkEvent.EventType.ENTERED) { 068 // change the mouse curor 069 vBox.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 070 } 071 if (e.getEventType() == HyperlinkEvent.EventType.EXITED) { 072 vBox.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 073 } 074 } 075 }); 076 077 078 JButton close = new JButton("Close"); 079 080 close.addActionListener(new ActionListener(){ 081 @Override 082 public void actionPerformed(ActionEvent event) { 083 Object source = event.getSource(); 084 085 JButton but = (JButton)source; 086 Container parent = but.getParent().getParent().getParent().getParent().getParent().getParent() ; 087 088 JDialog dia = (JDialog) parent; 089 dia.dispose(); 090 } 091 }); 092 093 Box hBoxb = Box.createHorizontalBox(); 094 hBoxb.add(Box.createGlue()); 095 hBoxb.add(close,BorderLayout.EAST); 096 097 vBox.add(hBoxb); 098 099 dialog.getContentPane().add(vBox); 100 dialog.setVisible(true); 101 102 103 104 } 105}