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.BorderLayout;
   29   import java.awt.Component;
   30   import java.awt.GridBagConstraints;
   31   import java.awt.GridBagLayout;
   32   import java.awt.Insets;
   33   
   34   import javax.swing.BorderFactory;
   35   import javax.swing.DefaultListCellRenderer;
   36   import javax.swing.Icon;
   37   import javax.swing.JComboBox;
   38   import javax.swing.JLabel;
   39   import javax.swing.JList;
   40   import javax.swing.JPanel;
   41   import javax.swing.UIManager;
   42   
   43   
   44   /**
   45    *
   46    *
   47    * @author $author$
   48    * @version $Revision: 1.14 $
   49    */
   50   public class GlobalOptionsTab extends JPanel implements OptionsTab {
   51       /**  */
   52       public final static String GLOBAL_ICON = "largeglobal.png";
   53   
   54       //
   55       private JComboBox lafChooser;
   56   
   57       /**
   58   * Creates a new GlobalOptionsTab object.
   59   */
   60       public GlobalOptionsTab() {
   61           super();
   62   
   63           Insets ins = new Insets(2, 2, 2, 2);
   64           JPanel s = new JPanel(new GridBagLayout());
   65           GridBagConstraints gbc1 = new GridBagConstraints();
   66           gbc1.weighty = 1.0;
   67           gbc1.insets = ins;
   68           gbc1.anchor = GridBagConstraints.NORTHWEST;
   69           gbc1.fill = GridBagConstraints.HORIZONTAL;
   70           gbc1.weightx = 0.0;
   71           UIUtil.jGridBagAdd(s, new JLabel("Look and feel"), gbc1,
   72               GridBagConstraints.RELATIVE);
   73           gbc1.weightx = 1.0;
   74           UIUtil.jGridBagAdd(s,
   75               lafChooser = new JComboBox(
   76                       SshToolsApplication.getAllLookAndFeelInfo()), gbc1,
   77               GridBagConstraints.REMAINDER);
   78           lafChooser.setRenderer(new LAFRenderer());
   79   
   80           IconWrapperPanel w = new IconWrapperPanel(new ResourceIcon(
   81                       GlobalOptionsTab.class, GLOBAL_ICON), s);
   82   
   83           //  This tab
   84           setLayout(new BorderLayout());
   85           add(w, BorderLayout.CENTER);
   86           setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
   87           reset();
   88       }
   89   
   90       /**
   91   *
   92   */
   93       public void reset() {
   94           String sel = PreferencesStore.get(SshToolsApplication.PREF_LAF,
   95                   UIManager.getLookAndFeel().getClass().getName());
   96   
   97           for (int i = 0; i < lafChooser.getModel().getSize(); i++) {
   98               if (((UIManager.LookAndFeelInfo) lafChooser.getModel().getElementAt(i)).getClassName()
   99                        .equals(sel)) {
  100                   lafChooser.setSelectedIndex(i);
  101   
  102                   break;
  103               }
  104           }
  105       }
  106   
  107       /**
  108   *
  109   *
  110   * @return
  111   */
  112       public String getTabContext() {
  113           return "Options";
  114       }
  115   
  116       /**
  117   *
  118   *
  119   * @return
  120   */
  121       public Icon getTabIcon() {
  122           return null;
  123       }
  124   
  125       /**
  126   *
  127   *
  128   * @return
  129   */
  130       public String getTabTitle() {
  131           return "Global";
  132       }
  133   
  134       /**
  135   *
  136   *
  137   * @return
  138   */
  139       public String getTabToolTipText() {
  140           return "Global options.";
  141       }
  142   
  143       /**
  144   *
  145   *
  146   * @return
  147   */
  148       public int getTabMnemonic() {
  149           return 'g';
  150       }
  151   
  152       /**
  153   *
  154   *
  155   * @return
  156   */
  157       public Component getTabComponent() {
  158           return this;
  159       }
  160   
  161       /**
  162   *
  163   *
  164   * @return
  165   */
  166       public boolean validateTab() {
  167           return true;
  168       }
  169   
  170       /**
  171   *
  172   */
  173       public void applyTab() {
  174           PreferencesStore.put(SshToolsApplication.PREF_LAF,
  175               ((UIManager.LookAndFeelInfo) lafChooser.getSelectedItem()).getClassName());
  176       }
  177   
  178       /**
  179   *
  180   */
  181       public void tabSelected() {
  182       }
  183   
  184       class LAFRenderer extends DefaultListCellRenderer {
  185           public Component getListCellRendererComponent(JList list, Object value,
  186               int index, boolean isSelected, boolean cellHasFocus) {
  187               super.getListCellRendererComponent(list, value, index, isSelected,
  188                   cellHasFocus);
  189               setText(((UIManager.LookAndFeelInfo) value).getName());
  190   
  191               return this;
  192           }
  193       }
  194   }

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