Java tutorial
/* * Funambol is a mobile platform developed by Funambol, Inc. * Copyright (C) 2008 Funambol, Inc. * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License version 3 as published by * the Free Software Foundation with the addition of the following permission * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. * * 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 Affero General Public License * along with this program; if not, see http://www.gnu.org/licenses or write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA. * * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License * version 3, these Appropriate Legal Notices must retain the display of the * "Powered by Funambol" logo. If the display of the logo is not reasonably * feasible for technical reasons, the Appropriate Legal Notices must display * the words "Powered by Funambol". */ package com.funambol.exchange.admin; import java.io.Serializable; import java.awt.Component; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JCheckBox; import javax.swing.SwingConstants; import javax.swing.border.TitledBorder; import org.apache.commons.lang.StringUtils; import com.funambol.admin.AdminException; import com.funambol.admin.ui.GuiFactory; import com.funambol.admin.util.Log; /** * This class implements the connector configuration panel * for a Exchange Connector component * * * @version $Id$ */ public class DefaultExchangeConnectorConfigPanel extends JPanel { // --------------------------------------------------------------- Constants public static final String PORT_ALLOWED_CHARS = "0123456789"; public static final String NAME_ALLOWED_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_."; // ------------------------------------------------------------ Private data private JTextField contactFolderValue; private JTextField eventFolderValue; private JTextField taskFolderValue; private JTextField noteFolderValue; private JTextField seccServerValue; private JTextField seccPortValue; private JTextField exchangeServerValue; private JCheckBox useSSLValue; private JCheckBox useFBAValue; private JCheckBox useKeyStoreValue; private JLabel keyStoreFileNameLabel; private JTextField keyStoreFileNameValue; private JLabel keyStorePasswordLabel; private JTextField keyStorePasswordValue; private JLabel exchangeServerNameLabel; private JTextField exchangeServerNameValue; private JButton confirmButton = new JButton(); private JButton cancelButton = new JButton(); private ExchangeConnectorConfigPanel configPanel; private ExchangeUserConfig exchangeConf = null; // ------------------------------------------------------------ Constructors public DefaultExchangeConnectorConfigPanel() { init(); } // --------------------------------------------------------- Private methods /** * Create the panel */ private void init() { JLabel title, contactFolderLabel, eventFolderLabel, taskFolderLabel, noteFolderLabel, seccServerLabel, seccPortLabel, exchangeServerLabel; JPanel seccPanel, exchangePanel, sslPanel; title = new JLabel(); exchangePanel = new JPanel(); seccPanel = new JPanel(); sslPanel = new JPanel(); contactFolderValue = new JTextField(); eventFolderValue = new JTextField(); taskFolderValue = new JTextField(); noteFolderValue = new JTextField(); seccServerLabel = new JLabel(); seccServerValue = new JTextField(); seccPortLabel = new JLabel(); seccPortValue = new JTextField(); useSSLValue = new JCheckBox(); useFBAValue = new JCheckBox(); useKeyStoreValue = new JCheckBox(); keyStoreFileNameLabel = new JLabel(); keyStoreFileNameValue = new JTextField(); keyStorePasswordLabel = new JLabel(); keyStorePasswordValue = new JTextField(); exchangeServerLabel = new JLabel(); exchangeServerValue = new JTextField(); exchangeServerNameLabel = new JLabel(); exchangeServerNameValue = new JTextField(); setLayout(null); title.setFont(GuiFactory.titlePanelFont); title.setText("Funambol Exchange Connector"); title.setBounds(new Rectangle(14, 5, 316, 28)); title.setAlignmentX(SwingConstants.CENTER); title.setBorder(new TitledBorder("")); contactFolderLabel = new JLabel(); contactFolderLabel.setText("Contact Folder: "); contactFolderLabel.setBounds(14, 35, 116, 15); add(contactFolderLabel); contactFolderValue.setBounds(150, 35, 220, 19); add(contactFolderValue); eventFolderLabel = new JLabel(); eventFolderLabel.setText("Event Folder: "); eventFolderLabel.setBounds(14, 65, 116, 15); add(eventFolderLabel); eventFolderValue.setBounds(150, 65, 220, 19); add(eventFolderValue); taskFolderLabel = new JLabel(); taskFolderLabel.setText("Task Folder: "); taskFolderLabel.setBounds(14, 95, 116, 15); add(taskFolderLabel); taskFolderValue.setBounds(150, 95, 220, 19); add(taskFolderValue); noteFolderLabel = new JLabel(); noteFolderLabel.setText("Note Folder: "); noteFolderLabel.setBounds(14, 125, 116, 15); add(noteFolderLabel); noteFolderValue.setBounds(150, 125, 220, 19); add(noteFolderValue); seccPanel.setLayout(null); seccPanel.setBorder(new TitledBorder("HTTP Server Configuration")); seccServerLabel.setText("Server:"); seccPanel.add(seccServerLabel); seccServerLabel.setBounds(10, 20, 116, 15); seccPanel.add(seccServerValue); seccServerValue.setBounds(150, 20, 220, 19); seccServerValue.setFont(GuiFactory.defaultFont); seccPortLabel.setText("Port:"); seccPanel.add(seccPortLabel); seccPortLabel.setBounds(10, 50, 131, 15); seccPanel.add(seccPortValue); seccPortValue.setBounds(150, 50, 220, 19); seccPortValue.setFont(GuiFactory.defaultFont); add(seccPanel); seccPanel.setBounds(10, 155, 380, 80); exchangePanel.setLayout(null); exchangePanel.setBorder(new TitledBorder("WebDav Message Configuration")); exchangeServerLabel.setText("Server: "); exchangePanel.add(exchangeServerLabel); exchangeServerLabel.setBounds(10, 20, 150, 19); exchangePanel.add(exchangeServerValue); exchangeServerValue.setBounds(150, 20, 220, 19); exchangeServerValue.setFont(GuiFactory.defaultFont); exchangeServerNameLabel.setText("Name:"); exchangeServerNameLabel.setBounds(10, 50, 150, 19); exchangePanel.add(exchangeServerNameLabel); exchangeServerNameValue.setBounds(150, 50, 220, 19); exchangeServerNameValue.setFont(GuiFactory.defaultFont); exchangePanel.add(exchangeServerNameValue); add(exchangePanel); exchangePanel.setBounds(10, 255, 380, 80); //the ssl option panel sslPanel.setLayout(null); sslPanel.setBorder(new TitledBorder("SSL")); useSSLValue.setText("Use SSL"); useSSLValue.setSelected(false); useSSLValue.setBounds(5, 20, 150, 19); sslPanel.add(useSSLValue); useFBAValue.setText("Use Form-Based Authentication"); useFBAValue.setSelected(true); useFBAValue.setBounds(5, 40, 250, 19); sslPanel.add(useFBAValue); useKeyStoreValue.setText("Use Keystore"); useKeyStoreValue.setSelected(false); useKeyStoreValue.setBounds(5, 60, 200, 19); sslPanel.add(useKeyStoreValue); useKeyStoreValue.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent acEvent) { boolean enabled = useKeyStoreValue.isSelected(); keyStoreFileNameLabel.setEnabled(enabled); keyStoreFileNameValue.setEnabled(enabled); keyStorePasswordLabel.setEnabled(enabled); keyStorePasswordValue.setEnabled(enabled); } }); keyStoreFileNameLabel.setText("Key Store File: "); sslPanel.add(keyStoreFileNameLabel); keyStoreFileNameLabel.setEnabled(false); keyStoreFileNameLabel.setBounds(10, 80, 131, 15); sslPanel.add(keyStoreFileNameValue); keyStoreFileNameValue.setEnabled(false); keyStoreFileNameValue.setBounds(150, 80, 220, 19); keyStoreFileNameValue.setFont(GuiFactory.defaultFont); keyStorePasswordLabel.setText("Key Store Password: "); sslPanel.add(keyStorePasswordLabel); keyStorePasswordLabel.setEnabled(false); keyStorePasswordLabel.setBounds(10, 110, 131, 15); sslPanel.add(keyStorePasswordValue); keyStorePasswordValue.setEnabled(false); keyStorePasswordValue.setBounds(150, 110, 220, 19); keyStorePasswordValue.setFont(GuiFactory.defaultFont); add(sslPanel); sslPanel.setBounds(10, 355, 450, 140); confirmButton.setFont(GuiFactory.defaultFont); confirmButton.setText("Save"); add(confirmButton); confirmButton.setBounds(120, 500, 70, 25); confirmButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { getValues(); configPanel.saveDefaultConfig(event.getActionCommand()); configPanel.finishedDefaultConfig(); } }); cancelButton.setFont(GuiFactory.defaultFont); cancelButton.setText("Cancel"); add(cancelButton); cancelButton.setBounds(200, 500, 70, 25); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { configPanel.finishedDefaultConfig(); } }); // // Setting font... // Component[] components = getComponents(); for (int i = 0; (components != null) && (i < components.length); ++i) { components[i].setFont(GuiFactory.defaultFont); } // // We add it as the last one so that the font won't be changed // add(title); } /** * Load values from the config to the form. */ public void loadValues() { exchangeConf = configPanel.getDefaultConfig(); if (exchangeConf == null) { return; } contactFolderValue.setText(exchangeConf.getContactsFolder()); eventFolderValue.setText(exchangeConf.getEventsFolder()); taskFolderValue.setText(exchangeConf.getTasksFolder()); noteFolderValue.setText(exchangeConf.getNotesFolder()); exchangeServerValue.setText(exchangeConf.getExchangeServer()); exchangeServerNameValue.setText(exchangeConf.getExchangeServerName()); seccServerValue.setText(exchangeConf.getSeccServer()); seccPortValue.setText(String.valueOf(exchangeConf.getSeccPort())); useSSLValue.setSelected(exchangeConf.isUseSsl()); useFBAValue.setSelected(exchangeConf.isUseFba()); useKeyStoreValue.setSelected(exchangeConf.isUseKeyStore()); keyStoreFileNameValue.setEnabled(exchangeConf.isUseKeyStore()); keyStoreFileNameValue.setText(exchangeConf.getKeyStoreFileName()); keyStoreFileNameLabel.setEnabled(exchangeConf.isUseKeyStore()); keyStorePasswordValue.setEnabled(exchangeConf.isUseKeyStore()); keyStorePasswordValue.setText(exchangeConf.getKeyStorePassword()); keyStorePasswordLabel.setEnabled(exchangeConf.isUseKeyStore()); } /** * Set properties with the values provided by the user. */ private void getValues() { if (exchangeConf == null) { return; } exchangeConf.setContactsFolder(contactFolderValue.getText().trim()); exchangeConf.setEventsFolder(eventFolderValue.getText().trim()); exchangeConf.setTasksFolder(taskFolderValue.getText().trim()); exchangeConf.setNotesFolder(noteFolderValue.getText().trim()); exchangeConf.setExchangeServer(exchangeServerValue.getText().trim()); exchangeConf.setExchangeServer(exchangeServerValue.getText().trim()); exchangeConf.setSeccServer(seccServerValue.getText().trim()); exchangeConf.setSeccPort(Integer.parseInt(seccPortValue.getText().trim())); exchangeConf.setUseSsl(useSSLValue.isSelected()); exchangeConf.setUseFba(useFBAValue.isSelected()); exchangeConf.setUseKeyStore(useKeyStoreValue.isSelected()); if (exchangeConf.isUseKeyStore()) { exchangeConf.setKeyStoreFileName(keyStoreFileNameValue.getText()); exchangeConf.setKeyStorePassword(keyStorePasswordValue.getText()); } } /** * Method to set the instance of the ExchangeConnectorConfigPanel. * @param panel */ public void setConnectorConfigPanel(ExchangeConnectorConfigPanel panel) { configPanel = panel; } }