1 22 23 package org.gjt.sp.jedit.help; 24 25 import org.gjt.sp.jedit.*; 27 import org.gjt.sp.jedit.gui.RolloverButton; 28 import java.awt.*; 29 import java.awt.event.*; 30 import javax.swing.*; 31 import javax.swing.event.*; 32 34 39 public class HistoryButton extends JPanel implements ActionListener 40 { 41 public static final int BACK = 0; 42 public static final int FORWARD = 1; 43 44 private int type; 46 private HelpHistoryModel history; 47 private RolloverButton arrow_button; 48 private RolloverButton drop_button; 49 private JPopupMenu historyList; 50 private ActionListener arrowActionListener; 51 53 public HistoryButton(int type, HelpHistoryModel model) 55 { 56 super(); 57 arrow_button = new RolloverButton(GUIUtilities.loadIcon( 58 jEdit.getProperty( 59 (type==BACK? 60 "helpviewer.back.icon" 61 : 62 "helpviewer.forward.icon" 63 )))); 64 arrow_button.setToolTipText( 65 jEdit.getProperty((type==BACK? 66 "helpviewer.back.label" 67 : 68 "helpviewer.forward.label" 69 ))); 70 Box box = new Box(BoxLayout.X_AXIS); 71 drop_button = new RolloverButton(GUIUtilities.loadIcon("ToolbarMenu.gif")); 72 drop_button.addActionListener(new DropActionHandler()); 73 box.add(arrow_button); 74 box.add(drop_button); 75 this.setMaximumSize(new Dimension( 76 drop_button.getPreferredSize().width + 77 arrow_button.getPreferredSize().width + 78 5, 79 arrow_button.getPreferredSize().height+10) 80 ); 81 this.add(box); 82 this.type = type; 83 this.history = model; 84 } 86 public void setEnabled(boolean state) 88 { 89 super.setEnabled(state); 90 drop_button.setEnabled(state); 91 arrow_button.setEnabled(state); 92 } 94 public void addActionListener(ActionListener al) 96 { 97 arrow_button.addActionListener(this); 98 arrowActionListener = al; 99 } 101 public void actionPerformed(ActionEvent evt) 103 { 104 arrowActionListener.actionPerformed( 105 new ActionEvent(this, 106 ActionEvent.ACTION_PERFORMED, 107 evt.getActionCommand(), 108 evt.getWhen(), 109 evt.getModifiers() 110 ) 111 ); 112 } 114 private HistoryButton getParentHistoryButton() 116 { 117 return this; 118 } 120 122 class DropActionHandler implements ActionListener 124 { 125 public void actionPerformed(ActionEvent evt) 127 { 128 historyList = new JPopupMenu(); 129 HelpHistoryModel.HistoryEntry[] urls; 130 if (type == BACK) 131 urls = history.getPreviousURLs(); 132 else 133 urls = history.getNextURLs(); 134 if (urls != null) 135 { 136 if (type==BACK) { 137 for (int i=urls.length-1;i>=0;i--) 138 if (urls[i]!=null) 139 historyList.add(new HistoryListActionHandler(urls[i])); 140 } 141 else 142 { 143 for (int i=0;i<urls.length;i++) 144 if (urls[i]!=null) 145 historyList.add(new HistoryListActionHandler(urls[i])); 146 } 147 148 149 historyList.show((JComponent)evt.getSource(),0,0); 150 } 151 } } 154 class HistoryListActionHandler extends AbstractAction 156 { 157 HelpHistoryModel.HistoryEntry entry; 158 159 HistoryListActionHandler(HelpHistoryModel.HistoryEntry entry) 161 { 162 super(entry.title); 163 this.entry = entry; 164 this.putValue(Action.ACTION_COMMAND_KEY,entry.url); 165 } 167 public void actionPerformed(ActionEvent ae) 169 { 170 history.setCurrentEntry(entry); 171 getParentHistoryButton().actionPerformed(ae); 172 } } 175 } 177 178 | Popular Tags |