/*******************************************************************************
* HelloNzb -- The Binary Usenet Tool
* Copyright (C) 2010-2013 Matthias F. Brandstetter
* https://sourceforge.net/projects/hellonzb/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package me.mabra.hellonzb.preferences.tabs;
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import me.mabra.hellonzb.HelloNzb;
import me.mabra.hellonzb.preferences.ServerSelectionListener;
import me.mabra.hellonzb.util.NumericTextField;
import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
public class PrefServerTab extends PrefTabPanel
{
protected static final String [] keys = new String [] { "ServerSettingsHost",
"ServerSettingsPort",
"ServerSettingsUseSSL",
"ServerSettingsThreadCount",
"ServerSettingsUsername",
"ServerSettingsPassword",
"ServerSettingsBackupHost",
"ServerSettingsBackupPort",
"ServerSettingsBackupUseSSL",
"ServerSettingsBackupThreadCount",
"ServerSettingsBackupUsername",
"ServerSettingsBackupPassword" };
public static String [] getKeys() { return keys; }
/** standard server port text field */
protected NumericTextField stdServerPort;
/** Std/SSL selection check box */
protected JCheckBox stdSslCB;
/** Switches between default and alternative server settings, keeps their current values */
protected ServerSelectionListener serverSelectionListener;
public PrefServerTab(HelloNzb h, HashMap<String,String> prefMap)
{
super(h, prefMap);
createPanel();
}
private void createPanel()
{
String sepString = null;
CompContainer compc = new CompContainer(null, null);
// create layout for this tab/panel
FormLayout layout = new FormLayout(
"right:pref, 3dlu, pref:grow, 3dlu, [20dlu,pref]", // cols
"p, 9dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, p, 3dlu, p, 3dlu, p, 3dlu, p"); // rows
// create builder
PanelBuilder builder = new PanelBuilder(layout, panel);
builder.setDefaultDialogBorder();
CellConstraints cc = new CellConstraints();
// default/alternative toggle buttons
JToggleButton btnDefaultServer = new JToggleButton(localer.getBundleText("ServerSettingsDefaultServer"), true);
JToggleButton btnBackupServer = new JToggleButton(localer.getBundleText("ServerSettingsAlternativeServer"), false);
serverSelectionListener = new ServerSelectionListener(this, btnDefaultServer, btnBackupServer);
btnDefaultServer.addItemListener(serverSelectionListener);
btnBackupServer.addItemListener(serverSelectionListener);
JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
btnPanel.add(btnDefaultServer);
btnPanel.add(btnBackupServer);
ButtonGroup btnGroup = new ButtonGroup();
btnGroup.add(btnDefaultServer);
btnGroup.add(btnBackupServer);
builder.add(new JLabel(localer.getBundleText("ServerSettingsServerSelection")), cc.xy(1, 1));
builder.add(btnPanel, cc.xy(3, 1));
//////////////////////////////////////////////////////////////////////
// group "connection"
sepString = localer.getBundleText("ServerSettingsGroupConnection");
builder.add(createSeparator(sepString), cc.xyw(1, 3, 5));
// host
createTextfield(compc, "ServerSettingsHost", "JTextField");
if(prefMap.get("ServerSettingsHost").equals(""))
((JTextField)compc.comp).setText("example.host.com");
builder.add(compc.label, cc.xy(1, 5));
builder.add(compc.comp, cc.xy(3, 5));
// port
createTextfield(compc, "ServerSettingsPort", "NumericTextField");
if(prefMap.get("ServerSettingsPort").equals(""))
((JTextField)compc.comp).setText("119");
stdServerPort = (NumericTextField) compc.comp;
builder.add(compc.label, cc.xy(1, 7));
builder.add(compc.comp, cc.xy(3, 7));
// "use SSL connections" checkbox
createCheckbox(compc, "ServerSettingsUseSSL", false);
stdSslCB = (JCheckBox) compc.comp;
builder.add(compc.label, cc.xy(1, 9));
builder.add(compc.comp, cc.xy(3, 9));
// create slider and add to layout (via new row)
createSlider(compc, "ServerSettingsThreadCount", 1, 51, 1, 5, 1, "");
builder.add(compc.label, cc.xy(1, 11));
builder.add(compc.comp, cc.xy(3, 11));
builder.add(compc.extraLabel, cc.xy(5, 11));
//////////////////////////////////////////////////////////////////////
// group "authentication"
sepString = localer.getBundleText("ServerSettingsGroupAuthentication");
builder.add(createSeparator(sepString), cc.xyw(1, 13, 5));
// username
createTextfield(compc, "ServerSettingsUsername", "JTextField");
builder.add(compc.label, cc.xy(1, 15));
builder.add(compc.comp, cc.xy(3, 15));
// password
createTextfield(compc, "ServerSettingsPassword", "JPasswordField");
builder.add(compc.label, cc.xy(1, 17));
builder.add(compc.comp, cc.xy(3, 17));
}
@Override
public String [] keys()
{
return getKeys();
}
public NumericTextField getStdServerPort()
{
return stdServerPort;
}
@Override
public String getSettingsValue(String key)
{
return serverSelectionListener.getSettingsValue(key);
}
}