001: /*
002: * HistoryButton.java - History Button
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2005 Nicholas O'Leary
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.help;
024:
025: //{{{ Imports
026: import org.gjt.sp.jedit.*;
027: import org.gjt.sp.jedit.gui.RolloverButton;
028: import java.awt.*;
029: import java.awt.event.*;
030: import javax.swing.*;
031: import javax.swing.event.*;
032:
033: //}}}
034:
035: /**
036: * History Button
037: * @author Nicholas O'Leary
038: * @version $Id: HistoryButton.java 9197 2007-03-22 14:35:05Z Vampire0 $
039: */
040: public class HistoryButton extends JPanel implements ActionListener {
041: public static final int BACK = 0;
042: public static final int FORWARD = 1;
043:
044: //{{{ Private Members
045: private int type;
046: private HelpHistoryModel history;
047: private RolloverButton arrow_button;
048: private RolloverButton drop_button;
049: private JPopupMenu historyList;
050: private ActionListener arrowActionListener;
051:
052: //}}}
053:
054: //{{{ HistoryButton constructor
055: public HistoryButton(int type, HelpHistoryModel model) {
056: super ();
057: arrow_button = new RolloverButton(GUIUtilities.loadIcon(jEdit
058: .getProperty(type == BACK ? "helpviewer.back.icon"
059: : "helpviewer.forward.icon")));
060: arrow_button.setToolTipText(jEdit
061: .getProperty(type == BACK ? "helpviewer.back.label"
062: : "helpviewer.forward.label"));
063: Box box = new Box(BoxLayout.X_AXIS);
064: drop_button = new RolloverButton(GUIUtilities
065: .loadIcon("ToolbarMenu.gif"));
066: drop_button.addActionListener(new DropActionHandler());
067: box.add(arrow_button);
068: box.add(drop_button);
069: this .setMaximumSize(new Dimension(drop_button
070: .getPreferredSize().width
071: + arrow_button.getPreferredSize().width + 5,
072: arrow_button.getPreferredSize().height + 10));
073: this .add(box);
074: this .type = type;
075: this .history = model;
076: } //}}}
077:
078: //{{{ setEnabled() method
079: public void setEnabled(boolean state) {
080: super .setEnabled(state);
081: drop_button.setEnabled(state);
082: arrow_button.setEnabled(state);
083: } //}}}
084:
085: //{{{ addActionListener() method
086: public void addActionListener(ActionListener al) {
087: arrow_button.addActionListener(this );
088: arrowActionListener = al;
089: } //}}}
090:
091: //{{{ actionPerformed() method
092: public void actionPerformed(ActionEvent evt) {
093: arrowActionListener.actionPerformed(new ActionEvent(this ,
094: ActionEvent.ACTION_PERFORMED, evt.getActionCommand(),
095: evt.getWhen(), evt.getModifiers()));
096: } //}}}
097:
098: //{{{ getParentHistoryButton() method
099: private HistoryButton getParentHistoryButton() {
100: return this ;
101: } //}}}
102:
103: //{{{ Inner Classes
104:
105: //{{{ DropActionHandler class
106: class DropActionHandler implements ActionListener {
107: //{{{ actionPerformed() method
108: public void actionPerformed(ActionEvent evt) {
109: historyList = new JPopupMenu();
110: HelpHistoryModel.HistoryEntry[] urls;
111: if (type == BACK) {
112: urls = history.getPreviousURLs();
113: } else {
114: urls = history.getNextURLs();
115: }
116: if (urls != null) {
117: if (type == BACK) {
118: for (int i = urls.length - 1; i >= 0; i--) {
119: if (urls[i] != null) {
120: historyList
121: .add(new HistoryListActionHandler(
122: urls[i]));
123: }
124: }
125: } else {
126: for (int i = 0; i < urls.length; i++) {
127: if (urls[i] != null) {
128: historyList
129: .add(new HistoryListActionHandler(
130: urls[i]));
131: }
132: }
133: }
134:
135: historyList.show((JComponent) evt.getSource(), 0, 0);
136: }
137: } //}}}
138: } //}}}
139:
140: //{{{ HistoryListActionHandler class
141: class HistoryListActionHandler extends AbstractAction {
142: HelpHistoryModel.HistoryEntry entry;
143:
144: //{{{ HistoryListActionHandler constructor
145: HistoryListActionHandler(HelpHistoryModel.HistoryEntry entry) {
146: super (entry.title);
147: this .entry = entry;
148: this .putValue(Action.ACTION_COMMAND_KEY, entry.url + ':'
149: + entry.scrollPosition);
150: } //}}}
151:
152: //{{{ actionPerformed() method
153: public void actionPerformed(ActionEvent ae) {
154: getParentHistoryButton().actionPerformed(ae);
155: history.setCurrentEntry(entry);
156: } //}}}
157: } //}}}
158:
159: //}}}
160: }
|