Save This Page
Home » j2ssh-0.2.9-src » com.sshtools.common.ui » [javadoc | source]
    1   /*
    2    *  SSHTools - Java SSH2 API
    3    *
    4    *  Copyright (C) 2002-2003 Lee David Painter and Contributors.
    5    *
    6    *  Contributions made by:
    7    *
    8    *  Brett Smith
    9    *  Richard Pernavas
   10    *  Erwin Bolwidt
   11    *
   12    *  This program is free software; you can redistribute it and/or
   13    *  modify it under the terms of the GNU General Public License
   14    *  as published by the Free Software Foundation; either version 2
   15    *  of the License, or (at your option) any later version.
   16    *
   17    *  This program is distributed in the hope that it will be useful,
   18    *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   19    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20    *  GNU General Public License for more details.
   21    *
   22    *  You should have received a copy of the GNU General Public License
   23    *  along with this program; if not, write to the Free Software
   24    *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   25    */
   26   package com.sshtools.common.ui;
   27   
   28   import java.awt;
   29   
   30   import javax.swing;
   31   import javax.swing.event;
   32   
   33   
   34   /**
   35    *
   36    *
   37    * @author $author$
   38    * @version $Revision: 1.13 $
   39    */
   40   public class Tabber extends JTabbedPane {
   41       /**
   42   * Creates a new Tabber object.
   43   */
   44       public Tabber() {
   45           this(TOP);
   46       }
   47   
   48       /**
   49   * Creates a new Tabber object.
   50   *
   51   * @param tabPlacement
   52   */
   53       public Tabber(int tabPlacement) {
   54           super(tabPlacement);
   55           addChangeListener(new ChangeListener() {
   56                   public void stateChanged(ChangeEvent e) {
   57                       if (getSelectedIndex() != -1) {
   58                           getTabAt(getSelectedIndex()).tabSelected();
   59                       }
   60                   }
   61               });
   62       }
   63   
   64       /**
   65   *
   66   *
   67   * @param i
   68   *
   69   * @return
   70   */
   71       public Tab getTabAt(int i) {
   72           return ((TabPanel) getComponentAt(i)).getTab();
   73       }
   74   
   75       /**
   76   *
   77   *
   78   * @return
   79   */
   80       public boolean validateTabs() {
   81           for (int i = 0; i < getTabCount(); i++) {
   82               Tab tab = ((TabPanel) getComponentAt(i)).getTab();
   83   
   84               if (!tab.validateTab()) {
   85                   setSelectedIndex(i);
   86   
   87                   return false;
   88               }
   89           }
   90   
   91           return true;
   92       }
   93   
   94       /**
   95   *
   96   */
   97       public void applyTabs() {
   98           for (int i = 0; i < getTabCount(); i++) {
   99               Tab tab = ((TabPanel) getComponentAt(i)).getTab();
  100               tab.applyTab();
  101           }
  102       }
  103   
  104       /**
  105   *
  106   *
  107   * @param tab
  108   */
  109       public void addTab(Tab tab) {
  110           addTab(tab.getTabTitle(), tab.getTabIcon(), new TabPanel(tab),
  111               tab.getTabToolTipText());
  112       }
  113   
  114       class TabPanel extends JPanel {
  115           private Tab tab;
  116   
  117           TabPanel(Tab tab) {
  118               super(new BorderLayout());
  119               this.tab = tab;
  120               setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
  121               add(tab.getTabComponent(), BorderLayout.CENTER);
  122           }
  123   
  124           public Tab getTab() {
  125               return tab;
  126           }
  127       }
  128   }

Save This Page
Home » j2ssh-0.2.9-src » com.sshtools.common.ui » [javadoc | source]