Save This Page
Home » openjdk-7 » net » sf » bibkeeper » [javadoc | source]
    1   package net.sf.bibkeeper;
    2   
    3   import java.awt;
    4   import java.awt.event;
    5   import javax.swing;
    6   import javax.swing.event.HyperlinkListener;
    7   import javax.swing.event.HyperlinkEvent;
    8   import java.net.URL;
    9   
   10   /**
   11    * This is a non-modal help Dialog. The contents of the help is specified 
   12    * by calling 
   13    */
   14   public class HelpDialog extends JDialog implements HyperlinkListener {
   15   
   16       private BibtexBaseFrame parent;
   17       private HelpContent content;
   18       private BackAction back = new BackAction();
   19       private ForwardAction forward = new ForwardAction();
   20       private ContentsAction contents = new ContentsAction();
   21   
   22       // Initializes, but does not show the help dialog.
   23       public HelpDialog(BibtexBaseFrame bf) {
   24   	super(bf, GUIGlobals.helpTitle, false);
   25   	content = new HelpContent();
   26   	content.addHyperlinkListener(this);
   27   	setSize(GUIGlobals.helpSize);
   28   	Dimension ds = GUIGlobals.helpSize, 
   29   	    df = bf.getSetSize();
   30   	Point pf = bf.getSetLocation();
   31   	setLocation(new Point(Math.max(0,(pf.x+(df.width-ds.width)/2)),
   32   	Math.max(0,(pf.y+(df.height-ds.height)/2))));
   33   	/* There is probably no need for a window listener now, so it's commented out.
   34   	diag.addWindowListener(new WindowAdapter() {
   35   		public void windowClosing(WindowEvent e) {
   36   		    open = null;
   37   		}	       
   38   	    });*/
   39   	JToolBar tlb = new JToolBar();
   40   	//tlb.add(new CloseAction());
   41   	//tlb.addSeparator();
   42   	tlb.add(back);
   43   	tlb.add(forward);
   44   	tlb.addSeparator();
   45   	tlb.add(contents);
   46   	tlb.setFloatable(false);
   47   
   48   	// Make ESC close dialog, and set shortkeys for back and forward.
   49   	InputMap im = tlb.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
   50   	ActionMap am = tlb.getActionMap();
   51   	im.put(GUIGlobals.exitDialog, "close");
   52   	am.put("close", new CloseAction());
   53   	im.put(GUIGlobals.switchPanelLeft, "left");
   54   	am.put("left", back);
   55   	im.put(GUIGlobals.switchPanelRight, "right");
   56   	am.put("right", forward);
   57   
   58   	// Set shortkeys for back and forward specifically for the EditorPane.
   59   	im = content.getInputMap(JComponent.WHEN_FOCUSED);
   60   	am = content.getActionMap();
   61   	im.put(GUIGlobals.switchPanelLeft, "left");
   62   	am.put("left", back);
   63   	im.put(GUIGlobals.switchPanelRight, "right");
   64   	am.put("right", forward);
   65   
   66   	getContentPane().add(tlb, BorderLayout.NORTH);
   67   	getContentPane().add(content.getPane());
   68   	forward.setEnabled(false);
   69   	back.setEnabled(false);
   70       }
   71   
   72       public void showPage(URL url) {
   73   	if (!isVisible()) {
   74   	    setVisible(true);
   75   	    content.reset();
   76   	    forward.setEnabled(false);
   77   	    back.setEnabled(false);
   78   	} else {
   79   	    setVisible(true);
   80   	    forward.setEnabled(false);
   81   	    back.setEnabled(true);
   82   	}
   83   	content.setPage(url);
   84   	content.requestFocus();
   85   	//setVisible(true);
   86       }
   87   
   88       public void hyperlinkUpdate(HyperlinkEvent e) {
   89   	if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
   90   	    content.setPage(e.getURL());
   91   	    back.setEnabled(true);
   92   	    forward.setEnabled(false);
   93   	}
   94       }
   95       
   96       class CloseAction extends AbstractAction {
   97   	public CloseAction() {
   98   	    super("Close", new ImageIcon(GUIGlobals.closeIconFile));
   99   	    putValue(SHORT_DESCRIPTION, "Close this help window");
  100   	}
  101   
  102   	public void actionPerformed(ActionEvent e) {
  103   	    dispose();	    
  104   	}
  105       }
  106   
  107       class BackAction extends AbstractAction {
  108   	public BackAction() {
  109   	    super("Back", new ImageIcon(GUIGlobals.backIconFile));
  110   	    //putValue(SHORT_DESCRIPTION, "Show the previous page");
  111   	}
  112   
  113   	public void actionPerformed(ActionEvent e) {
  114   	    setEnabled(content.back());
  115   	    forward.setEnabled(true);
  116   	}
  117       }
  118   
  119      class ForwardAction extends AbstractAction {
  120          public ForwardAction() {
  121   	   super("Forward", new ImageIcon(GUIGlobals.forwardIconFile));
  122          }
  123   
  124          public void actionPerformed(ActionEvent e) {
  125   	    setEnabled(content.forward());
  126   	    back.setEnabled(true);
  127          }
  128      }
  129   
  130      class ContentsAction extends AbstractAction {
  131          public ContentsAction() {
  132   	   super("Contents", new ImageIcon(GUIGlobals.contentsIconFile));
  133          }
  134   
  135          public void actionPerformed(ActionEvent e) {
  136   	   content.setPage(GUIGlobals.helpContents);
  137   	   back.setEnabled(true);
  138          }
  139      }
  140   }

Save This Page
Home » openjdk-7 » net » sf » bibkeeper » [javadoc | source]