View Javadoc

1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package net.sf.jour.rt.swingmonitor.ui.action;
22  
23  import java.awt.Component;
24  import java.awt.event.ActionEvent;
25  
26  import javax.swing.AbstractAction;
27  import javax.swing.JTabbedPane;
28  
29  import net.sf.jour.rt.swingmonitor.MonitoringJPanel;
30  
31  //import org.apache.log4j.Logger;
32  
33  /***
34   * TODO Add docs
35   *
36   * Created on 14.12.2004
37   * Contributing Author(s):
38   *
39   *   Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
40   *   Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
41   *
42   * @author vlads
43   * @version $Revision: 1.3 $ ($Author: vlads $)  $Date: 2004/12/16 05:35:54 $
44   */
45  public class CloseCurrentTabAction extends AbstractAction {
46  
47      private JTabbedPane tabbedPane = null;
48  
49      /***
50       * @param tabbedPane
51       */
52      public CloseCurrentTabAction(JTabbedPane tabbedPane) {
53          super("Close tab");
54          this.tabbedPane = tabbedPane;
55      }
56  
57      public boolean isEnabled() {
58          return true;
59      }
60  
61      public boolean isEnabled_TODO() {
62          Component comp = tabbedPane.getSelectedComponent();
63          if (!(comp instanceof MonitoringJPanel)) {
64              return true;
65          }
66          return ((MonitoringJPanel) comp).canCloseTab();
67      }
68  
69      /***
70       * Method actionPerformed
71       */
72      public void actionPerformed(ActionEvent e) {
73          if (!isEnabled_TODO()) {
74              return;
75          }
76          Component comp = tabbedPane.getSelectedComponent();
77          tabbedPane.remove(comp);
78      }
79  }