001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.common.ui;
027:
028: import java.awt.BorderLayout;
029: import java.awt.Component;
030: import java.awt.GridBagConstraints;
031: import java.awt.GridBagLayout;
032: import java.awt.Insets;
033:
034: import javax.swing.BorderFactory;
035: import javax.swing.DefaultListCellRenderer;
036: import javax.swing.Icon;
037: import javax.swing.JComboBox;
038: import javax.swing.JLabel;
039: import javax.swing.JList;
040: import javax.swing.JPanel;
041: import javax.swing.UIManager;
042:
043: /**
044: *
045: *
046: * @author $author$
047: * @version $Revision: 1.14 $
048: */
049: public class GlobalOptionsTab extends JPanel implements OptionsTab {
050: /** */
051: public final static String GLOBAL_ICON = "largeglobal.png";
052:
053: //
054: private JComboBox lafChooser;
055:
056: /**
057: * Creates a new GlobalOptionsTab object.
058: */
059: public GlobalOptionsTab() {
060: super ();
061:
062: Insets ins = new Insets(2, 2, 2, 2);
063: JPanel s = new JPanel(new GridBagLayout());
064: GridBagConstraints gbc1 = new GridBagConstraints();
065: gbc1.weighty = 1.0;
066: gbc1.insets = ins;
067: gbc1.anchor = GridBagConstraints.NORTHWEST;
068: gbc1.fill = GridBagConstraints.HORIZONTAL;
069: gbc1.weightx = 0.0;
070: UIUtil.jGridBagAdd(s, new JLabel("Look and feel"), gbc1,
071: GridBagConstraints.RELATIVE);
072: gbc1.weightx = 1.0;
073: UIUtil.jGridBagAdd(s, lafChooser = new JComboBox(
074: SshToolsApplication.getAllLookAndFeelInfo()), gbc1,
075: GridBagConstraints.REMAINDER);
076: lafChooser.setRenderer(new LAFRenderer());
077:
078: IconWrapperPanel w = new IconWrapperPanel(new ResourceIcon(
079: GlobalOptionsTab.class, GLOBAL_ICON), s);
080:
081: // This tab
082: setLayout(new BorderLayout());
083: add(w, BorderLayout.CENTER);
084: setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
085: reset();
086: }
087:
088: /**
089: *
090: */
091: public void reset() {
092: String sel = PreferencesStore.get(SshToolsApplication.PREF_LAF,
093: UIManager.getLookAndFeel().getClass().getName());
094:
095: for (int i = 0; i < lafChooser.getModel().getSize(); i++) {
096: if (((UIManager.LookAndFeelInfo) lafChooser.getModel()
097: .getElementAt(i)).getClassName().equals(sel)) {
098: lafChooser.setSelectedIndex(i);
099:
100: break;
101: }
102: }
103: }
104:
105: /**
106: *
107: *
108: * @return
109: */
110: public String getTabContext() {
111: return "Options";
112: }
113:
114: /**
115: *
116: *
117: * @return
118: */
119: public Icon getTabIcon() {
120: return null;
121: }
122:
123: /**
124: *
125: *
126: * @return
127: */
128: public String getTabTitle() {
129: return "Global";
130: }
131:
132: /**
133: *
134: *
135: * @return
136: */
137: public String getTabToolTipText() {
138: return "Global options.";
139: }
140:
141: /**
142: *
143: *
144: * @return
145: */
146: public int getTabMnemonic() {
147: return 'g';
148: }
149:
150: /**
151: *
152: *
153: * @return
154: */
155: public Component getTabComponent() {
156: return this ;
157: }
158:
159: /**
160: *
161: *
162: * @return
163: */
164: public boolean validateTab() {
165: return true;
166: }
167:
168: /**
169: *
170: */
171: public void applyTab() {
172: PreferencesStore.put(SshToolsApplication.PREF_LAF,
173: ((UIManager.LookAndFeelInfo) lafChooser
174: .getSelectedItem()).getClassName());
175: }
176:
177: /**
178: *
179: */
180: public void tabSelected() {
181: }
182:
183: class LAFRenderer extends DefaultListCellRenderer {
184: public Component getListCellRendererComponent(JList list,
185: Object value, int index, boolean isSelected,
186: boolean cellHasFocus) {
187: super .getListCellRendererComponent(list, value, index,
188: isSelected, cellHasFocus);
189: setText(((UIManager.LookAndFeelInfo) value).getName());
190:
191: return this;
192: }
193: }
194: }
|