View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.gui;
21  
22  import java.awt.Component;
23  import java.util.Iterator;
24  import java.util.LinkedList;
25  
26  import javax.help.CSH;
27  import javax.swing.JToolBar;
28  
29  import org.xnap.gui.action.ActionHelper;
30  import org.xnap.gui.action.PluginDialogAction;
31  import org.xnap.gui.action.PreferencesDialogAction;
32  import org.xnap.gui.action.ShowHotlistAction;
33  import org.xnap.gui.component.XNapToolBarButton;
34  import org.xnap.gui.component.XNapToolBarToggleButton;
35  
36  /***
37   * The MainToolBar is shown at the top of the main application window.
38   */
39  public class MainToolBar extends JToolBar
40  {
41      //--- Constant(s) ---
42      
43      //--- Data field(s) ---
44  
45      /***
46       * A list of components that is added temporarily to this toolbar.
47       */
48      private LinkedList temporaries = new LinkedList();
49  
50      //--- Constructor(s) ---
51  
52      public MainToolBar()
53      {
54  		add(new XNapToolBarButton(new PluginDialogAction()));
55  		add(new XNapToolBarButton(new PreferencesDialogAction()));
56  
57  		add(new XNapToolBarButton
58  			(ActionHelper.pluginPreferencesDialogAction));
59  
60  // 		if (XNap.isRunFromCvs()) {
61  // 			add(new XNapToolBarButton(new ErrorAction()));
62  //		}
63  		addSeparator();
64  		add(new XNapToolBarToggleButton(new ShowHotlistAction()));
65  		addSeparator();
66  		add(new XNapToolBarButton(ActionHelper.cutAction));
67  		add(new XNapToolBarButton(ActionHelper.copyAction));
68  		add(new XNapToolBarButton(ActionHelper.pasteAction));
69  		addSeparator();
70  
71  		// help
72  		CSH.setHelpIDString(this, "main-toolbar");
73      }
74  
75      //--- Method(s) ---
76  
77      /***
78       * Adds <code>c</code>. 
79       *
80       * @see #removeAllTemporaries()
81       */
82      public void addTemporary(Component c)
83      {
84  		add(c);
85  		temporaries.add(c);
86      }
87  
88      /***
89       * Removes all components that were added by
90       * {@link #addTemporary(Component)}.
91       */
92      public void removeAllTemporaries()
93      {
94  		for (Iterator i = temporaries.iterator(); i.hasNext();) {
95  			remove((Component)i.next());
96  		}
97  		temporaries.clear();
98      }
99  }