📄 signaturedialog.java
字号:
/*** $Id: SignatureDialog.java,v 1.4 2001/05/07 12:37:22 kunugi Exp $**** Copyright (c) 2000-2001 Jeff Gay** on behalf of ICEMail.org <http://www.icemail.org>** Copyright (c) 1998-2000 by Timothy Gerard Endres** ** This program is free software.** ** You may redistribute it and/or modify it under the terms of the GNU** General Public License as published by the Free Software Foundation.** Version 2 of the license should be included with this distribution in** the file LICENSE, as well as License.html. If the license is not** included with this distribution, you may find a copy at the FSF web** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.**** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR** REDISTRIBUTION OF THIS SOFTWARE. */package org.icemail.mail;import java.awt.BorderLayout;import java.awt.Container;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Frame;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Vector;import javax.swing.JButton;import javax.swing.JDialog; import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.border.EmptyBorder;import org.icemail.util.AWTUtilities; import org.icemail.util.ComponentFactory; import org.icemail.util.JFCUtilities; import org.icemail.util.UserProperties; /** * A dialog which allows signitures to be created, modified and deleted. * The options are stored as part of the configuration properties. * * @see Configuration */public class SignatureDialog extends JDialog{ private JList sigList; private JTextField nameField; private JTextArea signText; private JTextField namespaceField; /** * Construct a dialog for maintaining signitures. * * @param parent parent frame to return to after disposed */ public SignatureDialog( Frame parent ) { super( parent, true ); establishContents(); pack(); Dimension sz = getSize(); int w = UserProperties.getProperty( "signatureDialog.width", sz.width ); int h = UserProperties.getProperty( "signatureDialog.height", sz.height ); setSize( w, h ); setLocation( AWTUtilities.computeDialogLocation( this ) ); validate(); }//............................................................ private void saveField() { String sigName = this.nameField.getText(); String signature = this.signText.getText(); Vector list = UserProperties.getStringVector( Configuration.P_SIG_LIST, new Vector() ); if ( ! list.contains( sigName ) ) { list.addElement( sigName ); this.sigList.setListData( list ); Configuration.getInstance().setStringArray( Configuration.P_SIG_LIST, list ); } Configuration.getInstance().setProperty( Configuration.PP_SIGNATURE + sigName, signature ); Configuration.getInstance().saveProperties(); this.sigList.setSelectedValue( sigName, true ); this.sigList.repaint( 100 ); } private void deleteField() { String sigName = this.nameField.getText(); String signature = this.signText.getText(); Vector list = UserProperties.getStringVector( Configuration.P_SIG_LIST, new Vector() ); if ( list.contains( sigName ) ) { list.removeElement( sigName ); this.sigList.setListData( list ); this.sigList.repaint( 100 ); clearFields(); Configuration.getInstance().setStringArray( Configuration.P_SIG_LIST, list ); Configuration.getInstance().removeProperty( Configuration.PP_SIGNATURE + sigName ); Configuration.getInstance().saveProperties(); } } private void clearFields() { this.nameField.setText( "" ); this.signText.setText( "" ); this.sigList.getSelectionModel().clearSelection(); this.nameField.requestFocus(); } private void establishContents() { setTitle( ICEMail.getBundle().getString( "Signature.Title" ) ); Container cont = getContentPane(); cont.setLayout( new GridBagLayout() ); ActionListener xlistener = new IActionListener(); int row = 0; String[] nameList = UserProperties.getStringArray( Configuration.P_SIG_LIST, null ); if ( nameList == null ) this.sigList = new JList(); else this.sigList = new JList( nameList ); this.sigList.addListSelectionListener( new SelectionListener() ); JScrollPane scroller = new JScrollPane(); scroller.getViewport().add( this.sigList ); JPanel fieldPan = new JPanel(); fieldPan.setLayout( new GridBagLayout() ); fieldPan.setBorder( new EmptyBorder( 4, 4, 4, 4 ) ); int subRow = 0; JLabel lbl; lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "Signature.Name" ); lbl.setHorizontalAlignment( JLabel.RIGHT ); AWTUtilities.constrain( fieldPan, lbl, GridBagConstraints.NONE, GridBagConstraints.WEST, 0, subRow, 1, 1, 0.0, 0.0 ); this.nameField = ComponentFactory.getTextField ( ICEMail.getBundle(), "Signature.Name", null ); AWTUtilities.constrain( fieldPan, this.nameField, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 1, subRow++, 1, 1, 1.0, 0.0 ); lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "Signature.Signature" ); lbl.setHorizontalAlignment( JLabel.LEFT ); AWTUtilities.constrain( fieldPan, lbl, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 0, subRow++, 2, 1, 1.0, 0.0 ); this.signText = new JTextArea(); JScrollPane signScroll = new JScrollPane(); signScroll.getViewport().add( this.signText ); signScroll.setPreferredSize( new Dimension( 450, 150 ) ); AWTUtilities.constrain( fieldPan, signScroll, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST, 0, subRow++, 2, 1, 1.0, 1.0 ); JPanel btnPan = new JPanel(); btnPan.setLayout( new GridLayout( 2, 2, 10, 10) ); btnPan.setBorder( new EmptyBorder( 6, 6, 6, 6 ) ); JButton btn; btn = ComponentFactory.getButton( ICEMail.getBundle(), "Signature.Save", xlistener, null ); btnPan.add( btn ); btn = ComponentFactory.getButton( ICEMail.getBundle(), "Signature.Clear", xlistener, null ); btnPan.add( btn ); btn = ComponentFactory.getButton( ICEMail.getBundle(), "Signature.Delete", xlistener, null ); btnPan.add( btn ); btn = ComponentFactory.getButton( ICEMail.getBundle(), "Signature.Close", xlistener, null ); btnPan.add( btn ); JPanel listPan = new JPanel(); listPan.setLayout( new BorderLayout() ); listPan.setBorder( JFCUtilities.StandardBorder ); listPan.add( scroller, BorderLayout.CENTER ); scroller.setPreferredSize( new Dimension( 100, 70 ) ); AWTUtilities.constrain( cont, listPan, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 0, 0, 1, 1, 0.3, 0.0 ); AWTUtilities.constrain( cont, btnPan, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 1, 0, 1, 1, 0.7, 0.0 ); AWTUtilities.constrain( cont, fieldPan, GridBagConstraints.BOTH, GridBagConstraints.NORTH, 0, 1, 2, 1, 1.0, 1.0 ); }//............................................................ private class IActionListener implements ActionListener { /** * Invoked when an action occurs. * <p> * Implementation of java.awt.event.ActionListener.actionPerformed() * * @param event the action event that occured */ public void actionPerformed( ActionEvent event ) { String command = event.getActionCommand(); if ( command.equals( "SAVE" ) ) { saveField(); } else if ( command.equals( "DELETE" ) ) { deleteField(); } else if ( command.equals( "CLEAR" ) ) { clearFields(); } else if ( command.equals( "CLOSE" ) ) { dispose(); } } }//............................................................ private class SelectionListener implements ListSelectionListener { public void valueChanged( ListSelectionEvent event ) { if ( ! event.getValueIsAdjusting() ) { String sigName = (String) sigList.getSelectedValue(); if ( sigName != null ) { nameField.setText( sigName ); String sigStr = UserProperties.getProperty( Configuration.PP_SIGNATURE + sigName, "" ); nameField.setText( sigName ); signText.setText( sigStr ); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -