mailoption.java

来自「Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI」· Java 代码 · 共 107 行

JAVA
107
字号
/*--------------------------------------------------------------------------*
 | Copyright (C) 2006 Christopher Kohlhaas                                  |
 |                                                                          |
 | 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. A copy of the license has been included with   |
 | these distribution in the COPYING file, if not go to www.fsf.org         |
 |                                                                          |
 | As a special exception, you are granted the permissions to link this     |
 | program with every library, which license fulfills the Open Source       |
 | Definition as published by the Open Source Initiative (OSI).             |
 *--------------------------------------------------------------------------*/
package org.rapla.plugin.mail.internal;

import java.awt.BorderLayout;
import java.util.Locale;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.rapla.components.calendar.RaplaNumber;
import org.rapla.components.layout.TableLayout;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaException;
import org.rapla.gui.DefaultPluginOption;
import org.rapla.gui.OptionPanel;
import org.rapla.plugin.mail.MailPlugin;

public class MailOption extends DefaultPluginOption implements OptionPanel {
   
    JTextField mailServer = new JTextField();
    RaplaNumber smtpPortField = new RaplaNumber(new Integer(25), new Integer(0),null,false);
    JTextField defaultSender = new JTextField();
    JCheckBox booleanField = new JCheckBox();
    
    public MailOption(RaplaContext sm) throws RaplaException {
        super(sm);
    }

    protected JPanel createPanel() throws RaplaException {
        JPanel panel = super.createPanel();
        JPanel content = new JPanel();
        double[][] sizes = new double[][] {
            {5,TableLayout.PREFERRED, 5,TableLayout.FILL,5}
            ,{TableLayout.PREFERRED,5,TableLayout.PREFERRED, 5, TableLayout.PREFERRED, 5, TableLayout.PREFERRED, 5, TableLayout.PREFERRED}
        };
        TableLayout tableLayout = new TableLayout(sizes);
        content.setLayout(tableLayout);
        content.add(new JLabel("Mail Server"), "1,0");
        content.add( mailServer, "3,0");
        content.add(new JLabel("Mail Port"), "1,2");
        content.add( smtpPortField, "3,2");
        content.add(new JLabel("Use Java Mail API*"), "1,4");
        content.add(booleanField,"3,4");
        content.add(new JLabel("Default Sender"), "1,6");
        content.add( defaultSender, "3,6");
        content.add( new JLabel("*Require the mailapi-jars on classpath (e.g.WEB-INF/lib)"), "3,8");
        
        panel.add( content, BorderLayout.CENTER);
        return panel;
    }

        
    protected void addChildren( DefaultConfiguration newConfig) {
        DefaultConfiguration smtpPort = new DefaultConfiguration("smtp-port");
        DefaultConfiguration smtpServer = new DefaultConfiguration("smtp-host");
        smtpPort.setValue(smtpPortField.getNumber().intValue() );
        smtpServer.setValue( mailServer.getText());
        newConfig.setAttribute( "usemailapi", booleanField.isSelected() );
        newConfig.addChild( smtpPort );
        newConfig.addChild( smtpServer );
    }

    protected void readConfig( Configuration config)   {
        booleanField.setSelected( config.getAttributeAsBoolean("usemailapi", false));
        mailServer.setText( config.getChild("smtp-host").getValue("localhost"));
        smtpPortField.setNumber( new Integer(config.getChild("smtp-port").getValueAsInteger(25)));
    }

    public void show() throws RaplaException  {
        super.show();
        defaultSender.setText( preferences.getEntryAsString(MailPlugin.DEFAULT_SENDER_ENTRY,"rapla"));
    }
  
    public void commit() throws RaplaException {
        super.commit();
        preferences.putEntry(MailPlugin.DEFAULT_SENDER_ENTRY,String.valueOf( defaultSender.getText() ));
    }


    /**
     * @see org.rapla.gui.DefaultPluginOption#getDescriptorClassName()
     */
    public String getDescriptorClassName() {
        return MailPlugin.class.getName();
    }
    
    public String getName(Locale locale) {
        return "Mail Plugin";
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?