git-svn-id: https://svn.coded.pt/svn/SIPRP@597 bb69d46d-e84e-40c8-a05a-06db0d633741

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Frederico Palma 18 years ago
parent 6ce0a8db7c
commit f939252fe2

@ -3,8 +3,13 @@ package siprp.medicina.processo.mail;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Vector;
import javax.swing.Action;
import javax.swing.ActionMap;
@ -12,14 +17,23 @@ import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledEditorKit;
import javax.swing.text.html.HTMLEditorKit;
import com.evolute.utils.images.ImageIconLoader;
public class MailPanel extends JPanel
{
protected StyledEditorKit.FontSizeAction FONT_SIZE_ACTIONS[];
protected int FONT_SIZES[];
protected JTextPane bodyPane;
public static void main( String args[] )
throws Exception
{
JFrame frm = new JFrame();
frm.getContentPane().setLayout( new GridLayout( 1, 1 ) );
@ -35,13 +49,49 @@ public class MailPanel extends JPanel
}
public MailPanel()
throws Exception
{
setupComponents();
}
private void setupComponents()
throws Exception
{
HTMLEditorKit kit = new HTMLEditorKit();
Action actions[] = kit.getActions();
Vector<StyledEditorKit.FontSizeAction> fontSizeActions =
new Vector<StyledEditorKit.FontSizeAction>();
for( int n = 0; n < actions.length; n++ )
{
String str = actions[ n ].getValue( Action.NAME ).toString();
if( str.toLowerCase().indexOf( "font-size" ) != -1 )
{
int size = Integer.parseInt( str.split( "-" )[ 2 ] );
if( size == 16 )
{
continue;
}
fontSizeActions.add( ( StyledEditorKit.FontSizeAction ) actions[ n ] );
}
}
FONT_SIZE_ACTIONS = fontSizeActions.toArray( new StyledEditorKit.FontSizeAction[ fontSizeActions.size() ] );
Arrays.sort( FONT_SIZE_ACTIONS, new Comparator<StyledEditorKit.FontSizeAction>(){
public int compare( StyledEditorKit.FontSizeAction fsa1, StyledEditorKit.FontSizeAction fsa2 )
{
String str1 = fsa1.getValue( Action.NAME ).toString();
String str2 = fsa2.getValue( Action.NAME ).toString();
int size1 = Integer.parseInt( str1.split( "-" )[ 2 ] );
int size2 = Integer.parseInt( str2.split( "-" )[ 2 ] );
return size1 > size2 ? 1 : -1;
}
} );
FONT_SIZES = new int[ FONT_SIZE_ACTIONS.length ];
for( int n = 0; n < FONT_SIZES.length; n++ )
{
FONT_SIZES[ n ] = Integer.parseInt( FONT_SIZE_ACTIONS[ n ].getValue( Action.NAME ).toString().split( "-" )[ 2 ] );
}
bodyPane = new JTextPane();
bodyPane.setEditorKit( kit );
ActionMap actionMap = bodyPane.getActionMap();
@ -50,34 +100,101 @@ public class MailPanel extends JPanel
Action copyAction = actionMap.get( DefaultEditorKit.copyAction );
Action pasteAction = actionMap.get( DefaultEditorKit.pasteAction );
Action boldAction = actionMap.get( HTMLEditorKit.BOLD_ACTION );
Action italicAction = actionMap.get( HTMLEditorKit.ITALIC_ACTION );
Action boldAction = actionMap.get( "font-bold" );
Action italicAction = actionMap.get( "font-italic" );
Action underlineAction = actionMap.get( "font-underline" );
Action smallerAction = actionMap.get( HTMLEditorKit.FONT_CHANGE_SMALLER );
Action biggerAction = actionMap.get( HTMLEditorKit.FONT_CHANGE_BIGGER );
Action fontBiggerAction = new StyledEditorKit.FontSizeAction( "font-bigger", 30 ){
/**
*
*/
private static final long serialVersionUID = 1L;
public void actionPerformed( ActionEvent e )
{
bodyPane.requestFocusInWindow();
int start = bodyPane.getSelectionStart();
AttributeSet set = bodyPane.getStyledDocument().getCharacterElement( start ).getAttributes();
int size = StyleConstants.getFontSize( set );
for( int n = 0; n < FONT_SIZES.length; n++ )
{
if( size < FONT_SIZES[ n ] )
{
FONT_SIZE_ACTIONS[ n ].actionPerformed( e );
break;
}
}
}
};
Action fontSmallerAction =
new StyledEditorKit.FontSizeAction( "font-smaller", 5 ){
/**
*
*/
private static final long serialVersionUID = 1L;
public void actionPerformed( ActionEvent e )
{
bodyPane.requestFocusInWindow();
int start = bodyPane.getSelectionStart();
AttributeSet set = bodyPane.getStyledDocument().getCharacterElement( start ).getAttributes();
int size = StyleConstants.getFontSize( set );
for( int n = FONT_SIZES.length - 1; n >= 0; n-- )
{
if( size > FONT_SIZES[ n ] )
{
FONT_SIZE_ACTIONS[ n ].actionPerformed( e );
break;
}
}
}
};
Action alignLeftAction = actionMap.get( HTMLEditorKit.PARA_INDENT_LEFT );
Action alignLeftAction = actionMap.get( "left-justify" );
Action alignCenterAction = actionMap.get( "center-justify" );
Action alignRightAction = actionMap.get( HTMLEditorKit.PARA_INDENT_RIGHT );
Action alignRightAction = actionMap.get( "right-justify" );
Action alignJustifyAction =
new StyledEditorKit.AlignmentAction( "justify",
javax.swing.text.StyleConstants.ALIGN_JUSTIFIED );
actionMap.put( "justify", alignJustifyAction );
JButton exportButton = new JButton( "X" );
exportButton.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent e )
{
System.out.println( bodyPane.getText() );
}
} );
JPanel upperPanel = new JPanel();
upperPanel.setLayout( new FlowLayout( FlowLayout.LEFT ) );
upperPanel.add( new JButton( cutAction ) );
upperPanel.add( new JButton( copyAction ) );
upperPanel.add( new JButton( pasteAction ) );
upperPanel.add( new JButton( boldAction ) );
upperPanel.add( new JButton( italicAction ) );
upperPanel.add( new JButton( underlineAction ) );
upperPanel.add( new JButton( smallerAction ) );
upperPanel.add( new JButton( biggerAction ) );
upperPanel.add( new JButton( alignLeftAction ) );
upperPanel.add( new JButton( alignCenterAction ) );
upperPanel.add( new JButton( alignRightAction ) );
upperPanel.add( exportButton );
upperPanel.add( createButton( cutAction, "siprp/medicina/processo/mail/icons/cut.png" ) );
upperPanel.add( createButton( copyAction, "siprp/medicina/processo/mail/icons/copy.png" ) );
upperPanel.add( createButton( pasteAction, "siprp/medicina/processo/mail/icons/paste.png" ) );
upperPanel.add( createButton( boldAction, "siprp/medicina/processo/mail/icons/text_bold.png" ) );
upperPanel.add( createButton( italicAction, "siprp/medicina/processo/mail/icons/text_italics.png" ) );
upperPanel.add( createButton( underlineAction, "siprp/medicina/processo/mail/icons/text_underlined.png" ) );
upperPanel.add( createButton( fontBiggerAction, "siprp/medicina/processo/mail/icons/font_bigger.png" ) );
upperPanel.add( createButton( fontSmallerAction, "siprp/medicina/processo/mail/icons/font_smaller.png" ) );
upperPanel.add( createButton( alignLeftAction, "siprp/medicina/processo/mail/icons/text_align_left.png" ) );
upperPanel.add( createButton( alignCenterAction, "siprp/medicina/processo/mail/icons/text_align_center.png" ) );
upperPanel.add( createButton( alignRightAction, "siprp/medicina/processo/mail/icons/text_align_right.png" ) );
upperPanel.add( createButton( alignJustifyAction, "siprp/medicina/processo/mail/icons/text_align_justified.png" ) );
setLayout( new BorderLayout() );
add( upperPanel, BorderLayout.NORTH );
add( bodyPane, BorderLayout.CENTER );
}
private JButton createButton( Action action, String iconPath )
throws Exception
{
action.putValue( Action.SMALL_ICON,
ImageIconLoader.loadImageIcon( getClass(), iconPath ) );
JButton button = new JButton( action );
button.setText( null );
return button;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 791 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 469 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 823 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 849 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Loading…
Cancel
Save