|  |  | @ -12,11 +12,14 @@ import java.awt.event.ActionEvent; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.awt.event.ActionListener; |  |  |  | import java.awt.event.ActionListener; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.awt.event.ItemEvent; |  |  |  | import java.awt.event.ItemEvent; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.awt.event.ItemListener; |  |  |  | import java.awt.event.ItemListener; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import java.io.File; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.io.FileInputStream; |  |  |  | import java.io.FileInputStream; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.io.FileNotFoundException; |  |  |  | import java.io.FileNotFoundException; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.io.IOException; |  |  |  | import java.io.IOException; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.Arrays; |  |  |  | import java.util.Arrays; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.Comparator; |  |  |  | import java.util.Comparator; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import java.util.LinkedList; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import java.util.List; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.Vector; |  |  |  | import java.util.Vector; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import javax.swing.AbstractAction; |  |  |  | import javax.swing.AbstractAction; | 
			
		
	
	
		
		
			
				
					|  |  | @ -61,7 +64,7 @@ public class MailDialog extends CustomJDialog | 
			
		
	
		
		
			
				
					
					|  |  |  | 	protected JTextField bccText; |  |  |  | 	protected JTextField bccText; | 
			
		
	
		
		
			
				
					
					|  |  |  | 	protected JTextField subjectText; |  |  |  | 	protected JTextField subjectText; | 
			
		
	
		
		
			
				
					
					|  |  |  | 	protected BaseTable attachmentsTable; |  |  |  | 	protected BaseTable attachmentsTable; | 
			
		
	
		
		
			
				
					
					|  |  |  | 	protected VectorTableModel attachmentsModel; |  |  |  | 	protected VectorTableModel<String> attachmentsModel; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 	protected JTextPane bodyPane; |  |  |  | 	protected JTextPane bodyPane; | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 |  |  |  | 	 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	protected Action removeAttachmentAction; |  |  |  | 	protected Action removeAttachmentAction; | 
			
		
	
	
		
		
			
				
					|  |  | @ -109,7 +112,7 @@ public class MailDialog extends CustomJDialog | 
			
		
	
		
		
			
				
					
					|  |  |  | 		System.exit( 0 ); |  |  |  | 		System.exit( 0 ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | 	 |  |  |  | 	 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	public MailDialog( JFrame owner, String to, String bcc, String subject, String message ) |  |  |  | 	public MailDialog( JFrame owner, String to, String bcc, String subject, String message, Vector<File> files ) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 	throws Exception |  |  |  | 	throws Exception | 
			
		
	
		
		
			
				
					
					|  |  |  | 	{ |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  | 		super( owner, true ); |  |  |  | 		super( owner, true ); | 
			
		
	
	
		
		
			
				
					|  |  | @ -119,6 +122,7 @@ public class MailDialog extends CustomJDialog | 
			
		
	
		
		
			
				
					
					|  |  |  | 		setBcc( bcc ); |  |  |  | 		setBcc( bcc ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		setSubject( subject ); |  |  |  | 		setSubject( subject ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		setMessage( message ); |  |  |  | 		setMessage( message ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		attach( files ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		setModal( true ); |  |  |  | 		setModal( true ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		setSize( 1024, 768 ); |  |  |  | 		setSize( 1024, 768 ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		setVisible( true ); |  |  |  | 		setVisible( true ); | 
			
		
	
	
		
		
			
				
					|  |  | @ -194,10 +198,7 @@ public class MailDialog extends CustomJDialog | 
			
		
	
		
		
			
				
					
					|  |  |  | 				if( filename != null ) |  |  |  | 				if( filename != null ) | 
			
		
	
		
		
			
				
					
					|  |  |  | 				{ |  |  |  | 				{ | 
			
		
	
		
		
			
				
					
					|  |  |  | 					String dir = fd.getDirectory(); |  |  |  | 					String dir = fd.getDirectory(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 					String full = filename + " (" + dir + ")"; |  |  |  | 					attach( filename, dir ); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					Vector values = attachmentsModel.getValues(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 					values.add( full ); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 					attachmentsModel.setValues( values ); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 				} |  |  |  | 				} | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | 			} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		}; |  |  |  | 		}; | 
			
		
	
	
		
		
			
				
					|  |  | @ -242,10 +243,10 @@ public class MailDialog extends CustomJDialog | 
			
		
	
		
		
			
				
					
					|  |  |  | 		bccText.setEditable( false ); |  |  |  | 		bccText.setEditable( false ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		JLabel assuntoLabel = new JLabel( "Assunto:" ); |  |  |  | 		JLabel assuntoLabel = new JLabel( "Assunto:" ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		subjectText = new JTextField(); |  |  |  | 		subjectText = new JTextField(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		attachmentsModel = new VectorTableModel( new String[]{ "" } ); |  |  |  | 		attachmentsModel = new VectorTableModel<String>( new String[]{ "" } ); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		attachmentsTable = new BaseTable( attachmentsModel ); |  |  |  | 		attachmentsTable = new BaseTable( attachmentsModel ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		JScrollPane attachmentsScroll = new JScrollPane( attachmentsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, |  |  |  | //		JScrollPane attachmentsScroll = new JScrollPane( attachmentsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ); |  |  |  | //				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		attachmentsTable.getSelectionModel().addListSelectionListener( new ListSelectionListener(){ |  |  |  | 		attachmentsTable.getSelectionModel().addListSelectionListener( new ListSelectionListener(){ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 			@Override |  |  |  | 			@Override | 
			
		
	
	
		
		
			
				
					|  |  | @ -529,47 +530,52 @@ public class MailDialog extends CustomJDialog | 
			
		
	
		
		
			
				
					
					|  |  |  | 		String subject = subjectText.getText(); |  |  |  | 		String subject = subjectText.getText(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		String body = bodyPane.getText(); |  |  |  | 		String body = bodyPane.getText(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		String attachmentList[] = new String[ attachmentsTable.getRowCount() ]; |  |  |  | 		String attachmentList[] = new String[ attachmentsTable.getRowCount() ]; | 
			
		
	
		
		
			
				
					
					|  |  |  | 		byte attachments[][] = new byte[ attachmentsTable.getRowCount() ][]; |  |  |  | 		List<File> attachments = new LinkedList<File>(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		Vector values = attachmentsModel.getValues(); |  |  |  | 		Vector<String> values = attachmentsModel.getValues(); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		for( int n = 0; n < attachmentList.length; n++ ) |  |  |  | 		for( int n = 0; n < attachmentList.length; n++ ) | 
			
		
	
		
		
			
				
					
					|  |  |  | 		{ |  |  |  | 		{ | 
			
		
	
		
		
			
				
					
					|  |  |  | 			String str = ( String ) values.elementAt( n ); |  |  |  | 			String str = values.elementAt( n ); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			String name = str.substring( 0, str.indexOf( "(") - 1 ); |  |  |  | 			String name = str.substring( 0, str.indexOf( "(") - 1 ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			String path = str.substring( str.indexOf( "(") + 1, str.indexOf( ")") ); |  |  |  | 			String path = str.substring( str.indexOf( "(") + 1, str.indexOf( ")") ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 			try |  |  |  | //			try
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			{ |  |  |  | //			{
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				FileInputStream fis = new FileInputStream( path + name ); |  |  |  | 			File file = new File(path + name); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				Vector<byte[]> bytes = new Vector<byte[]>(); |  |  |  | 			if( file != null && file.exists() ) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				int available = 0; |  |  |  | 			{ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				int total = 0; |  |  |  | 				attachments.add(file); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				while( ( available = fis.available() ) > 0 ) |  |  |  | 			} | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				{ |  |  |  | //				FileInputStream fis = new FileInputStream( path + name );
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					byte b[] = new byte[ available ]; |  |  |  | //				Vector<byte[]> bytes = new Vector<byte[]>();
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					fis.read( b ); |  |  |  | //				int available = 0;
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					bytes.add( b ); |  |  |  | //				int total = 0;
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					total += available; |  |  |  | //				while( ( available = fis.available() ) > 0 )
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				} |  |  |  | //				{
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				attachments[ n ] = new byte[ total ]; |  |  |  | //					byte b[] = new byte[ available ];
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				int pos = 0; |  |  |  | //					fis.read( b );
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				for( byte[] chunk : bytes ) |  |  |  | //					bytes.add( b );
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				{ |  |  |  | //					total += available;
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					System.arraycopy( chunk, 0, attachments[ n ], pos, chunk.length ); |  |  |  | //				}
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					pos += chunk.length; |  |  |  | //				attachments[ n ] = new byte[ total ];
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				} |  |  |  | //				int pos = 0;
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | //				for( byte[] chunk : bytes )
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			catch( FileNotFoundException fnfex ) |  |  |  | //				{
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			{ |  |  |  | //					System.arraycopy( chunk, 0, attachments[ n ], pos, chunk.length );
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				JOptionPane.showMessageDialog( owner,  |  |  |  | //					pos += chunk.length;
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						"O ficheiro " + path + name + " n\u00e3o existe.", |  |  |  | //				}
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						"Ficheiro inexistente", |  |  |  | //			}
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 						JOptionPane.ERROR_MESSAGE ); |  |  |  | //			catch( FileNotFoundException fnfex )
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				return; |  |  |  | //			{
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | //				JOptionPane.showMessageDialog( owner, 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			catch( IOException ioex ) |  |  |  | //						"O ficheiro " + path + name + " n\u00e3o existe.",
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			{ |  |  |  | //						"Ficheiro inexistente",
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				DialogException.showExceptionMessage( ioex, "Erro a ler ficheiro " + path + name, true ); |  |  |  | //						JOptionPane.ERROR_MESSAGE );
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				return; |  |  |  | //				return;
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | //			}
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | //			catch( IOException ioex )
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | //			{
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | //				DialogException.showExceptionMessage( ioex, "Erro a ler ficheiro " + path + name, true );
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | //				return;
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | //			}
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		MailSender sender = new MailSender(); |  |  |  | 		MailSender sender = new MailSender(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		try |  |  |  | 		try | 
			
		
	
	
		
		
			
				
					|  |  | @ -593,4 +599,20 @@ public class MailDialog extends CustomJDialog | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} ); |  |  |  | 		} ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		 |  |  |  | 		 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	private void attach( Vector<File> files ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		for (File file  : files ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			attach( file.getName(), file.getParent() + File.separator ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	public void attach( String filename, String dir ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		String full = filename + " (" + dir + ")"; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Vector<String> values = attachmentsModel.getValues(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		values.add( full ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		attachmentsModel.setValues( values ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |