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 com.sshtools.common.configuration.SshToolsConnectionProfile;
029:
030: import com.sshtools.j2ssh.transport.cipher.SshCipherFactory;
031: import com.sshtools.j2ssh.transport.compression.SshCompressionFactory;
032: import com.sshtools.j2ssh.transport.hmac.SshHmacFactory;
033: import com.sshtools.j2ssh.transport.kex.SshKeyExchangeFactory;
034: import com.sshtools.j2ssh.transport.publickey.SshKeyPairFactory;
035:
036: import java.awt.Component;
037: import java.awt.GridBagConstraints;
038: import java.awt.GridBagLayout;
039: import java.awt.Insets;
040:
041: import java.util.Iterator;
042:
043: import javax.swing.BorderFactory;
044: import javax.swing.Icon;
045: import javax.swing.JComboBox;
046: import javax.swing.JLabel;
047: import javax.swing.JPanel;
048: import javax.swing.JSeparator;
049:
050: /**
051: *
052: *
053: * @author $author$
054: * @version $Revision: 1.15 $
055: */
056: public class SshToolsConnectionProtocolTab extends JPanel implements
057: SshToolsConnectionTab {
058: final static String KEYS_ICON = "/com/sshtools/common/ui/largekeys.png";
059: final static String PROTOCOL_ICON = "/com/sshtools/common/ui/largeprotocol.png";
060: final static String DEFAULT = "<Default>";
061:
062: //
063:
064: /** */
065: protected JComboBox jComboCipherCS = new JComboBox();
066:
067: /** */
068: protected JComboBox jComboCipherSC = new JComboBox();
069:
070: /** */
071: protected JComboBox jComboMacCS = new JComboBox();
072:
073: /** */
074: protected JComboBox jComboMacSC = new JComboBox();
075:
076: /** */
077: protected JComboBox jComboCompCS = new JComboBox();
078:
079: /** */
080: protected JComboBox jComboCompSC = new JComboBox();
081:
082: /** */
083: protected JComboBox jComboKex = new JComboBox();
084:
085: /** */
086: protected JComboBox jComboPK = new JComboBox();
087:
088: /** */
089: protected SshToolsConnectionProfile profile;
090:
091: /**
092: * Creates a new SshToolsConnectionProtocolTab object.
093: */
094: public SshToolsConnectionProtocolTab() {
095: super ();
096:
097: // Keys
098: JPanel keysPanel = new JPanel(new GridBagLayout());
099: GridBagConstraints gbc = new GridBagConstraints();
100: gbc.fill = GridBagConstraints.NONE;
101: gbc.anchor = GridBagConstraints.WEST;
102: gbc.insets = new Insets(2, 2, 2, 2);
103: gbc.weightx = 1.0;
104:
105: // Public key
106: UIUtil.jGridBagAdd(keysPanel, new JLabel("Public key"), gbc,
107: GridBagConstraints.REMAINDER);
108: gbc.fill = GridBagConstraints.HORIZONTAL;
109: UIUtil.jGridBagAdd(keysPanel, jComboPK, gbc,
110: GridBagConstraints.REMAINDER);
111: gbc.fill = GridBagConstraints.NONE;
112:
113: // Public key
114: UIUtil.jGridBagAdd(keysPanel, new JLabel("Key exchange"), gbc,
115: GridBagConstraints.REMAINDER);
116: gbc.fill = GridBagConstraints.HORIZONTAL;
117: UIUtil.jGridBagAdd(keysPanel, jComboKex, gbc,
118: GridBagConstraints.REMAINDER);
119: gbc.fill = GridBagConstraints.NONE;
120:
121: //
122: IconWrapperPanel iconKeysPanel = new IconWrapperPanel(
123: new ResourceIcon(KEYS_ICON), keysPanel);
124:
125: // Preferences
126: JPanel prefPanel = new JPanel(new GridBagLayout());
127: prefPanel
128: .setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
129: gbc = new GridBagConstraints();
130: gbc.fill = GridBagConstraints.NONE;
131: gbc.anchor = GridBagConstraints.WEST;
132: gbc.insets = new Insets(2, 2, 2, 2);
133: gbc.weightx = 1.0;
134:
135: // Public key
136: gbc.fill = GridBagConstraints.HORIZONTAL;
137: UIUtil.jGridBagAdd(prefPanel, new JLabel("Client - > Server"),
138: gbc, GridBagConstraints.RELATIVE);
139: UIUtil.jGridBagAdd(prefPanel, new JLabel("Server - > Client"),
140: gbc, GridBagConstraints.REMAINDER);
141:
142: // Separator
143: gbc.weightx = 2.0;
144: UIUtil.jGridBagAdd(prefPanel, new JSeparator(
145: JSeparator.HORIZONTAL), gbc,
146: GridBagConstraints.REMAINDER);
147:
148: // Cipher
149: UIUtil.jGridBagAdd(prefPanel, new JLabel("Cipher"), gbc,
150: GridBagConstraints.RELATIVE);
151: UIUtil.jGridBagAdd(prefPanel, new JLabel("Cipher"), gbc,
152: GridBagConstraints.REMAINDER);
153: UIUtil.jGridBagAdd(prefPanel, jComboCipherCS, gbc,
154: GridBagConstraints.RELATIVE);
155: UIUtil.jGridBagAdd(prefPanel, jComboCipherSC, gbc,
156: GridBagConstraints.REMAINDER);
157:
158: // Mac
159: UIUtil.jGridBagAdd(prefPanel, new JLabel("Mac"), gbc,
160: GridBagConstraints.RELATIVE);
161: UIUtil.jGridBagAdd(prefPanel, new JLabel("Mac"), gbc,
162: GridBagConstraints.REMAINDER);
163: UIUtil.jGridBagAdd(prefPanel, jComboMacCS, gbc,
164: GridBagConstraints.RELATIVE);
165: UIUtil.jGridBagAdd(prefPanel, jComboMacSC, gbc,
166: GridBagConstraints.REMAINDER);
167:
168: // Compression
169: UIUtil.jGridBagAdd(prefPanel, new JLabel("Compression"), gbc,
170: GridBagConstraints.RELATIVE);
171: UIUtil.jGridBagAdd(prefPanel, new JLabel("Compression"), gbc,
172: GridBagConstraints.REMAINDER);
173: UIUtil.jGridBagAdd(prefPanel, jComboCompCS, gbc,
174: GridBagConstraints.RELATIVE);
175: UIUtil.jGridBagAdd(prefPanel, jComboCompSC, gbc,
176: GridBagConstraints.REMAINDER);
177:
178: //
179: IconWrapperPanel iconPrefPanel = new IconWrapperPanel(
180: new ResourceIcon(PROTOCOL_ICON), prefPanel);
181:
182: // This tab
183: setLayout(new GridBagLayout());
184: setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
185: gbc = new GridBagConstraints();
186: gbc.fill = GridBagConstraints.NONE;
187: gbc.anchor = GridBagConstraints.WEST;
188: gbc.insets = new Insets(2, 2, 2, 2);
189: gbc.weightx = 1.0;
190: UIUtil.jGridBagAdd(this , iconKeysPanel, gbc,
191: GridBagConstraints.REMAINDER);
192: gbc.weighty = 1.0;
193: UIUtil.jGridBagAdd(this , iconPrefPanel, gbc,
194: GridBagConstraints.REMAINDER);
195:
196: //
197: loadList(SshCipherFactory.getSupportedCiphers(),
198: jComboCipherCS, true);
199: loadList(SshCipherFactory.getSupportedCiphers(),
200: jComboCipherSC, true);
201: loadList(SshHmacFactory.getSupportedMacs(), jComboMacCS, true);
202: loadList(SshHmacFactory.getSupportedMacs(), jComboMacSC, true);
203: loadList(SshCompressionFactory.getSupportedCompression(),
204: jComboCompCS, true);
205: loadList(SshCompressionFactory.getSupportedCompression(),
206: jComboCompSC, true);
207: loadList(SshKeyExchangeFactory.getSupportedKeyExchanges(),
208: jComboKex, true);
209: loadList(SshKeyPairFactory.getSupportedKeys(), jComboPK, true);
210: }
211:
212: /**
213: *
214: *
215: * @param profile
216: */
217: public void setConnectionProfile(SshToolsConnectionProfile profile) {
218: this .profile = profile;
219: jComboCipherCS.setSelectedItem(profile.getPrefCSEncryption());
220: jComboCipherSC.setSelectedItem(profile.getPrefSCEncryption());
221: jComboMacCS.setSelectedItem(profile.getPrefCSMac());
222: jComboMacSC.setSelectedItem(profile.getPrefSCMac());
223: jComboCompCS.setSelectedItem(profile.getPrefCSComp());
224: jComboCompSC.setSelectedItem(profile.getPrefSCComp());
225: jComboKex.setSelectedItem(profile.getPrefKex());
226: jComboPK.setSelectedItem(profile.getPrefPublicKey());
227: }
228:
229: /**
230: *
231: *
232: * @return
233: */
234: public SshToolsConnectionProfile getConnectionProfile() {
235: return profile;
236: }
237:
238: private void loadList(java.util.List list, JComboBox combo,
239: boolean addDefault) {
240: Iterator it = list.iterator();
241:
242: if (addDefault) {
243: combo.addItem(DEFAULT);
244: }
245:
246: while (it.hasNext()) {
247: combo.addItem(it.next());
248: }
249: }
250:
251: /**
252: *
253: *
254: * @return
255: */
256: public String getTabContext() {
257: return "Connection";
258: }
259:
260: /**
261: *
262: *
263: * @return
264: */
265: public Icon getTabIcon() {
266: return null;
267: }
268:
269: /**
270: *
271: *
272: * @return
273: */
274: public String getTabTitle() {
275: return "Protocol";
276: }
277:
278: /**
279: *
280: *
281: * @return
282: */
283: public String getTabToolTipText() {
284: return "Protocol related properties.";
285: }
286:
287: /**
288: *
289: *
290: * @return
291: */
292: public int getTabMnemonic() {
293: return 'p';
294: }
295:
296: /**
297: *
298: *
299: * @return
300: */
301: public Component getTabComponent() {
302: return this ;
303: }
304:
305: /**
306: *
307: *
308: * @return
309: */
310: public boolean validateTab() {
311: return true;
312: }
313:
314: /**
315: *
316: */
317: public void applyTab() {
318: // Get the algorithm preferences
319: if (!jComboCipherCS.getSelectedItem().equals(DEFAULT)) {
320: profile.setPrefCSEncryption((String) jComboCipherCS
321: .getSelectedItem());
322: }
323:
324: if (!jComboCipherSC.getSelectedItem().equals(DEFAULT)) {
325: profile.setPrefSCEncryption((String) jComboCipherSC
326: .getSelectedItem());
327: }
328:
329: if (!jComboMacCS.getSelectedItem().equals(DEFAULT)) {
330: profile
331: .setPrefCSMac((String) jComboMacCS
332: .getSelectedItem());
333: }
334:
335: if (!jComboMacSC.getSelectedItem().equals(DEFAULT)) {
336: profile
337: .setPrefSCMac((String) jComboMacSC
338: .getSelectedItem());
339: }
340:
341: if (!jComboCompCS.getSelectedItem().equals(DEFAULT)) {
342: profile.setPrefCSComp((String) jComboCompCS
343: .getSelectedItem());
344: }
345:
346: if (!jComboCompSC.getSelectedItem().equals(DEFAULT)) {
347: profile.setPrefSCComp((String) jComboCompSC
348: .getSelectedItem());
349: }
350:
351: if (!jComboKex.getSelectedItem().equals(DEFAULT)) {
352: profile.setPrefKex((String) jComboKex.getSelectedItem());
353: }
354:
355: if (!jComboPK.getSelectedItem().equals(DEFAULT)) {
356: profile.setPrefPublicKey((String) jComboPK
357: .getSelectedItem());
358: }
359: }
360:
361: /**
362: *
363: */
364: public void tabSelected() {
365: }
366: }
|