diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/MailPanel.java b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/MailPanel.java index b780e4da..97d4b9cf 100644 --- a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/MailPanel.java +++ b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/MailPanel.java @@ -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 fontSizeActions = + new Vector(); + 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(){ + 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; + } } diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/arrow_down.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/arrow_down.png new file mode 100644 index 00000000..ad8f6a36 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/arrow_down.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/arrow_down_green.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/arrow_down_green.png new file mode 100644 index 00000000..f2f03527 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/arrow_down_green.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/arrow_up_green.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/arrow_up_green.png new file mode 100644 index 00000000..cb9b87fd Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/arrow_up_green.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/bookmark_down.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/bookmark_down.png new file mode 100644 index 00000000..b15b51f9 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/bookmark_down.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/bullet_triangle_green.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/bullet_triangle_green.png new file mode 100644 index 00000000..b9c8cf49 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/bullet_triangle_green.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/colorwheel.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/colorwheel.png new file mode 100644 index 00000000..a655727e Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/colorwheel.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/copy.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/copy.png new file mode 100644 index 00000000..87cf5c96 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/copy.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/cut.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/cut.png new file mode 100644 index 00000000..bb623773 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/cut.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/font.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/font.png new file mode 100644 index 00000000..a87f6e45 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/font.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/mail_attachment.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/mail_attachment.png new file mode 100644 index 00000000..5af13794 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/mail_attachment.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/mail_forward.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/mail_forward.png new file mode 100644 index 00000000..92c427b0 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/mail_forward.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/mail_out.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/mail_out.png new file mode 100644 index 00000000..d21b5ea9 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/mail_out.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/paste.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/paste.png new file mode 100644 index 00000000..e3397b27 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/paste.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_center.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_center.png new file mode 100644 index 00000000..fceafc18 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_center.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_justified.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_justified.png new file mode 100644 index 00000000..639e7f63 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_justified.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_left.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_left.png new file mode 100644 index 00000000..d930bf9d Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_left.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_right.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_right.png new file mode 100644 index 00000000..6570be7f Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_align_right.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_bold.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_bold.png new file mode 100644 index 00000000..4fb8dd90 Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_bold.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_italics.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_italics.png new file mode 100644 index 00000000..14db2c1d Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_italics.png differ diff --git a/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_underlined.png b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_underlined.png new file mode 100644 index 00000000..0e5fb06c Binary files /dev/null and b/trunk/SIPRPSoft/src/siprp/medicina/processo/mail/icons/text_underlined.png differ