001 /*
002 Copyright (C) 2003 Adam Olsen
003
004 This program is free software; you can redistribute it and/or modify
005 it under the terms of the GNU General Public License as published by
006 the Free Software Foundation; either version 1, or (at your option)
007 any later version.
008
009 This program is distributed in the hope that it will be useful,
010 but WITHOUT ANY WARRANTY; without even the implied warranty of
011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 GNU General Public License for more details.
013
014 You should have received a copy of the GNU General Public License
015 along with this program; if not, write to the Free Software
016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
017 */
018
019 package com.valhalla.jbother.preferences;
020
021 import java.awt.GridBagConstraints;
022 import java.awt.GridBagLayout;
023 import java.util.*;
024 import java.net.InetAddress;
025 import java.net.Inet4Address;
026 import java.net.UnknownHostException;
027
028 import javax.swing.*;
029
030 import com.valhalla.gui.MJTextField;
031 import com.valhalla.settings.Settings;
032 import com.valhalla.settings.TempSettings;
033
034
035 /**
036 * preferences panel for file transfer-related settings.
037 *
038 * @author Lukasz Wiechec
039 * @created Feb 2, 2005 5:36:43 PM
040 * @version 1.0
041 */
042
043 public class DataTransferPreferencesPanel extends JPanel
044 implements PreferencesPanel
045 {
046 private static String[] PROXIES = new String[] { "proxy.netlab.cz:7777", "proxy65.jabber.autocom.pl:7777", "proxy.jabber.org:7777" };
047 private static String fId = "$Id$";
048
049 private ResourceBundle resources = ResourceBundle.getBundle(
050 "JBotherBundle", Locale.getDefault());
051
052 private GridBagLayout grid = new GridBagLayout();
053
054 private GridBagConstraints c = new GridBagConstraints();
055
056 private JLabel proxy65Label = new JLabel(resources.getString("preferredProxy65") + ": ");
057 private JLabel proxy65Note = new JLabel(resources.getString("proxy65Note"));
058 private JComboBox proxy65Host = new JComboBox(getProxies());
059 private JCheckBox preferIBB = new JCheckBox(resources.getString("preferIBB"));
060
061 public DataTransferPreferencesPanel(PreferencesDialog dialog)
062 {
063 setBorder(BorderFactory.createTitledBorder(resources.getString("dataTransfer")));
064 setLayout(grid);
065
066 c.gridx = 0;
067 c.gridy = 0;
068 c.fill = GridBagConstraints.NONE;
069 c.anchor = GridBagConstraints.WEST;
070 c.gridwidth = 1;
071 proxy65Host.setEditable(true);
072
073 // port
074 c.weightx = 0.0;
075 grid.setConstraints(proxy65Label, c);
076 add(proxy65Label);
077
078 c.gridx++;
079 grid.setConstraints(proxy65Host, c);
080 add(proxy65Host);
081
082 c.gridy++;
083 grid.setConstraints(proxy65Note, c);
084 add(proxy65Note);
085
086 c.gridx = 0;
087 c.gridy++;
088 c.gridwidth = 2;
089 grid.setConstraints(preferIBB, c);
090 add(preferIBB);
091
092 c.gridy++;
093 c.weightx = 1.0;
094 c.weighty = 1.0;
095 c.gridwidth = 2;
096 JLabel emptyLabel = new JLabel("");
097 grid.setConstraints(emptyLabel, c);
098 add(emptyLabel);
099
100 loadSettings();
101 }
102
103 public TempSettings getSettings()
104 {
105 TempSettings mySettings = new TempSettings();
106 mySettings.setProperty("proxy65Host", (String)proxy65Host.getSelectedItem());
107 mySettings.setBoolean("preferIBB", preferIBB.isSelected());
108
109 return mySettings;
110 }
111
112 private void loadSettings()
113 {
114 preferIBB.setSelected(Settings.getInstance().getBoolean("preferIBB"));
115 }
116
117 public static String[] getProxies()
118 {
119 String proxy = Settings.getInstance().getProperty("proxy65Host");
120
121 ArrayList proxies = new ArrayList();
122 if(proxy != null) proxies.add(proxy);
123
124 for(int i = 0; i < PROXIES.length; i++)
125 {
126 if(proxy == null || !proxy.equals(PROXIES[i]))
127 {
128 proxies.add(PROXIES[i]);
129 }
130 }
131
132 return (String[])proxies.toArray(new String[proxies.size()]);
133 }
134 }