📄 composeframe.java
字号:
} catch ( PasswordCancelException ex ) { Object[] xargs = { ex.getMessage() }; if ( xsign ) { ComponentFactory.showDialog( ICEMail.getBundle(), "Compose.MissingPass1", 0, JOptionPane.WARNING_MESSAGE, xargs ); } else { ComponentFactory.showDialog( ICEMail.getBundle(), "Compose.MissingPass2", 0, JOptionPane.WARNING_MESSAGE, xargs ); } } catch ( MessagingException xex ) { Object[] xargs = { xex.getMessage() }; ComponentFactory.showDialog( ICEMail.getBundle(), "Compose.SendingException", 0, JOptionPane.ERROR_MESSAGE, xargs ); } } private void saveComposition( Message message ) throws MessagingException { String xpath = UserProperties.getProperty( "composeFolderPath", null ); if ( xpath == null ) { ComposeConfigDialog xdialog = new ComposeConfigDialog( null ); xdialog.show(); xpath = UserProperties.getProperty( "composeFolderPath", null ); } if ( xpath != null && xpath.length() > 0 ) { MailUtilities.saveMessage( message, xpath ); } else { String xstring = ICEMail.getBundle().getString( "Exception.noFolderSpecified" ); throw new MessagingException( xstring ); } } private void collate( StringBuffer buf, String prefix, String text ) { boolean wasNewline = false; StringTokenizer toker = new StringTokenizer( text, "\n", true ); int count = toker.countTokens(); for ( int i = 0 ; i < count ; ++i ) { String textLine; try { textLine = toker.nextToken(); } catch ( NoSuchElementException ex ) { break; } if ( ! textLine.equals( "\n" ) ) { buf.append( prefix ); buf.append( textLine ); wasNewline = false; } else { if ( wasNewline ) { buf.append( prefix ); } buf.append( "\n" ); wasNewline = true; } } } private void setSignature( String sig ) { int selEnd = messageText_.getSelectionEnd(); int selStart = messageText_.getSelectionStart(); if ( signature_ != null ) { String msgText = messageText_.getText(); int index = -1; if ( signature_.length() > 0 ) { index = msgText.indexOf( signature_ ); } if ( index != -1 ) { selStart = index; messageText_.setCaretPosition( index ); messageText_.moveCaretPosition( index + signature_.length() ); } } signature_ = sig; messageText_.replaceSelection( sig ); selEnd = selStart + sig.length(); messageText_.setCaretPosition( selEnd ); messageText_.moveCaretPosition( selEnd ); modified_ = true; } private void establishContents() { Container content = getContentPane(); ((JPanel) content).setDoubleBuffered( true ); content.setLayout( new GridBagLayout() ); JToolBar xtoolBar = new JToolBar(); xtoolBar.setFloatable( false ); AWTUtilities.constrain( content, xtoolBar, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 0, 0, 1, 1, 0.5, 0.0 ); sendButton_ = ComponentFactory.getButton( ICEMail.getBundle(), "Compose.Send", actionListener_, focusListener_ ); xtoolBar.add( sendButton_ ); xtoolBar.addSeparator(); printButton_ = ComponentFactory.getButton( ICEMail.getBundle(), "Compose.Print", actionListener_, focusListener_ ); xtoolBar.add( printButton_ ); xtoolBar.addSeparator(); priorityButton_ = ComponentFactory.getRotateButton( ICEMail.getBundle(), "Compose.Priority", actionListener_, focusListener_ ); xtoolBar.add( priorityButton_ ); xtoolBar.addSeparator(); if ( ICEMail.getSMIMELibrary() != null ) { encryptButton_ = ComponentFactory.getRotateButton( ICEMail.getBundle(), "Compose.Encrypt", actionListener_, focusListener_ ); xtoolBar.add( encryptButton_ ); signButton_ = ComponentFactory.getRotateButton( ICEMail.getBundle(), "Compose.Sign", actionListener_, focusListener_ ); xtoolBar.add( signButton_ ); } JPanel comboPan = new JPanel(); comboPan.setLayout( new GridBagLayout() ); AWTUtilities.constrain( content, comboPan, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHEAST, 1, 0, 1, 1, 0.5, 0.0 ); JToolBar attachTools = new JToolBar(); attachTools.setFloatable( false ); AWTUtilities.constrain( comboPan, attachTools, GridBagConstraints.NONE, GridBagConstraints.EAST, 0, 0, 1, 1, 0.0, 0.0 ); attachButton_ = ComponentFactory.getButton( ICEMail.getBundle(), "Compose.Attach", actionListener_, focusListener_ ); attachTools.add( attachButton_ ); detachButton_ = ComponentFactory.getButton( ICEMail.getBundle(), "Compose.Detach", actionListener_, focusListener_ ); attachTools.add( detachButton_ ); attachComboBox_ = new JComboBox(); attachComboBox_.addFocusListener( focusListener_ ); AWTUtilities.constrain( comboPan, attachComboBox_, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 1, 0, 1, 1, 1.0, 0.0 ); JPanel xpanel = new JPanel(); xpanel.addFocusListener( focusListener_ ); xpanel.setLayout( new GridBagLayout() ); xpanel.setBorder( JFCUtilities.StandardBorder ); AWTUtilities.constrain( content, xpanel, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 0, 1, 2, 1, 1.0, 0.0 ); JLabel lbl; int row = 0; lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "Compose.From" ); AWTUtilities.constrain( xpanel, lbl, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0, row, 1, 1, 0.0, 0.0 ); fromText_ = ComponentFactory.getTextField( ICEMail.getBundle(), "Compose.From", focusListener_ ); AWTUtilities.constrain( xpanel, fromText_, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 1, row++, 1, 1, 1.0, 0.0 ); lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "Compose.To" ); AWTUtilities.constrain( xpanel, lbl, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0, row, 1, 1, 0.0, 0.0 ); toText_ = ComponentFactory.getTextField( ICEMail.getBundle(), "Compose.To", focusListener_ ); AWTUtilities.constrain( xpanel, toText_, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 1, row++, 1, 1, 1.0, 0.0 ); lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "Compose.Cc" ); AWTUtilities.constrain( xpanel, lbl, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0, row, 1, 1, 0.0, 0.0 ); ccText_ = ComponentFactory.getTextField( ICEMail.getBundle(), "Compose.Cc", focusListener_ ); AWTUtilities.constrain( xpanel, ccText_, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 1, row++, 1, 1, 1.0, 0.0 ); lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "Compose.Bcc" ); AWTUtilities.constrain( xpanel, lbl, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0, row, 1, 1, 0.0, 0.0 ); bccText_ = ComponentFactory.getTextField( ICEMail.getBundle(), "Compose.Bcc", focusListener_ ); AWTUtilities.constrain( xpanel, bccText_, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 1, row++, 1, 1, 1.0, 0.0 ); lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "Compose.Subject" ); AWTUtilities.constrain( xpanel, lbl, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0, row, 1, 1, 0.0, 0.0 ); subjectText_ = ComponentFactory.getTextField( ICEMail.getBundle(), "Compose.Subject", focusListener_ ); AWTUtilities.constrain( xpanel, subjectText_, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 1, row++, 1, 1, 1.0, 0.0 ); DefaultStyledDocument doc = new DefaultStyledDocument(); messageUndo_ = new UndoManager(); doc.addUndoableEditListener( messageUndo_ ); messageText_ = new JTextPane( doc ); JScrollPane xscrollPane = new JScrollPane(); xscrollPane.getViewport().add( messageText_ ); messageText_.getCaret().setBlinkRate( 500 ); messageText_.addFocusListener( focusListener_ ); AWTUtilities.constrain( content, xscrollPane, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 2, 2, 1, 2.0, 1.0 ); JPanel statusPan = new JPanel(); statusPan.setLayout( new GridBagLayout() ); AWTUtilities.constrain( content, statusPan, GridBagConstraints.HORIZONTAL, GridBagConstraints.SOUTHWEST, 0, 3, 1, 1, 1.0, 0.0 ); charsetLbl_ = new JLabel( (String) charsets_.firstElement() ); charsetMenu_ = new JPopupMenu(); for ( int i = 0, sz = charsets_.size() ; i < sz ; ++i ) { String cs = (String) charsets_.elementAt(i); Action act = new IAbstractAction( cs ); charsetMenu_.add( act ); } charsetLbl_.addMouseListener( new IMouseAdapter( charsetMenu_ ) ); AWTUtilities.constrain( statusPan, charsetLbl_, GridBagConstraints.HORIZONTAL, GridBagConstraints.SOUTHWEST, 0, 0, 1, 1, 1.0, 0.0 ); doc.addUndoableEditListener( new IUndoableEditListener() ); } private void establishMenuBar() { menuBar_ = new JMenuBar(); menuBar_.add( ComponentFactory.getMenuAndItems( ICEMail.getBundle(), "Compose.Message", actionListener_ ) ); menuBar_.add( ComponentFactory.getMenuAndItems( ICEMail.getBundle(), "Compose.Edit", actionListener_ ) ); establishSignatures(); establishAddresses(); setJMenuBar( menuBar_ ); } private void establishSignatures() { JMenuItem item; String sigListStr = UserProperties.getProperty( "signatureList", null ); JMenu menu = ComponentFactory.getMenuAndItems( ICEMail.getBundle(), "Compose.Sign", actionListener_ ); menuBar_.add( menu ); menu.addSeparator(); if ( sigListStr == null ) return; String[] sigList = StringUtilities.splitString( sigListStr, ":" ); for ( int i = 0 ; i < sigList.length ; ++i ) { if ( sigList[i].equals( "default" ) ) continue; String sigStr = UserProperties.getProperty( ("signature." + sigList[i]), null ); if ( sigStr == null ) continue; item = new JMenuItem( sigList[i] ); item.addActionListener( actionListener_ ); item.setActionCommand( "SIGN:" + sigList[i] ); menu.add( item ); } } private void establishAddresses() { JMenuItem item; String addrListStr = UserProperties.getProperty( "addressList", null ); if ( addrListStr == null ) return; String[] addrList = StringUtilities.splitString( addrListStr, ":" ); if ( addrList.length < 1 ) return; JMenu menu = ComponentFactory.getMenu( ICEMail.getBundle(), "Compose.Address" ); menuBar_.add( menu ); for ( int i = 0 ; i < addrList.length ; ++i ) { String addrStr = UserProperties.getProperty( ("address." + addrList[i]), null ); if ( addrStr == null ) continue; item = new JMenuItem( addrList[i] ); item.addActionListener( actionListener_ ); item.setActionCommand( "ADDR:" + addrList[i] ); if ( i < 10 ) item.setAccelerator( KeyStroke.getKeyStroke( ComposeFrame.AccKeys[i], Event.CTRL_MASK ) ); menu.add( item ); } }// ............................................................// these routines setup the contents of the composition private void setMessage( String body ) { try { Message xnew = null; if ( originalMessage_ != null ) { String xprefix = null; String xenclosure = null; boolean xuseattachments = false; Vector descV = new Vector(); Vector attachV = new Vector(); StringBuffer bodyBuf = new StringBuffer( 2046 ); MessageUtilities.decodeContent( originalMessage_, bodyBuf, attachV, descV ); // create or use the appropriate message switch ( state_ ) { case FORWARDING: xprefix = getForwardPrefix( originalMessage_ ); xenclosure = getForwardEnclosure( originalMessage_ ); xuseattachments = UserProperties.getProperty( Configuration.P_COMPOSE_FORWARD_ATTACHMENTS, true ); xnew = MessageUtilities.createForward( originalMessage_ ); break; case REPLYING: xprefix = getReplyPrefix( originalMessage_ ); xenclosure = getReplyEnclosure( originalMessage_ ); xnew = MessageUtilities.createReply( originalMessage_, "", false ); break; case REPLYINGTOALL: xprefix = getReplyPrefix( originalMessage_ ); xenclosure = getReplyEnclosure( originalMessage_ ); xnew = MessageUtilities.createReply( originalMessage_, "", true ); break; default: xuseattachments = true; xnew = originalMessage_; break; } // now convert the resulting message to the display fromText_.setText( MessageUtilities.decodeFrom( xnew ) ); toText_.setText( MessageUtilities.decodeAddresses( xnew, Message.RecipientType.TO ) ); ccText_.setText( MessageUtilities.decodeAddresses( xnew, Message.RecipientType.CC ) ); bccText_.setText( MessageUtilities.decodeAddresses( xnew, Message.RecipientType.BCC ) ); subjectText_.setText( xnew.getSubject() ); if ( body != null ) { messageText_.setText( body ); } else { messageText_.setText( bodyBuf.toString() ); } if ( xuseattachments ) { for ( int ai = 0, sz = attachV.size() ; ai < sz ; ai++ ) { // attachment Object ap = attachV.elementAt(ai); attachments_.addElement( ap ); // name
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -