001    /* $Id: JBook.java 12 2007-07-27 09:48:53Z ringler $
002     * This class is part of the de.mospace.swing library.
003     * Copyright (C) 2005-2006 Moritz Ringler
004     *
005     * This program is free software; you can redistribute it and/or
006     * modify it under the terms of the GNU General Public License
007     * as published by the Free Software Foundation; either version 2
008     * of the License, or (at your option) any later version.
009     *
010     * This program is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
018     */
019    package de.mospace.swing;
020    
021    import java.awt.Component;
022    import javax.swing.JTabbedPane;
023    
024    /** A {@link javax.swing.JTabbedPane JTabbedPane} where
025     * CTRL+T activates the next tab and to which tabs
026     * can be added conveniently.
027     *
028     * @author Moritz Ringler
029     * @version $Revision: 12 $ ($Date: 2007-07-27 11:48:53 +0200 (Fr, 27 Jul 2007) $)
030     * TODO: Fix Ctrl-T
031     */
032    public class JBook extends JTabbedPane{
033    
034        /** Constructs a new instance of this class. **/
035        public JBook(){
036            super();
037        }
038    
039        /** Binds CTRL+T to "next tab". (NOT WORKING!!!)*/
040        public void registerCtrlT(){
041            // KeyStroke ks = KeyStroke.
042                // getKeyStroke(KeyEvent.VK_T,InputEvent.CTRL_MASK);
043            // getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ks,"next");
044            // getActionMap().put("next",new AbstractAction(){
045                    // public void actionPerformed(ActionEvent e){
046                        // setSelectedIndex((getSelectedIndex()+1) % getTabCount());
047                    // }
048                // });
049        }
050    
051        /** Adds a tab named <code>name</code> and sets its mnemonic.
052         * @see java.awt.event.KeyEvent
053         */
054        public void add(Component component,String name, Integer mnemonic){
055            super.add(component,name);
056            int i = indexOfComponent(component);
057            setMnemonicAt(i,mnemonic.intValue());
058            setToolTipTextAt(i," ");
059        }
060    }