now change of style in xpad apply directly to all open tab
Allan SIMON [Wed, 16 Sep 2009 07:35:50 +0000 (09:35 +0200)]
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/ResetFontAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/SetColorsAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/SetFontAction.java

index b91e405..6c8d882 100644 (file)
@@ -3,6 +3,8 @@ package org.scilab.modules.xpad.actions;
 import java.awt.Font;
 import java.util.ArrayList;
 
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
 import javax.swing.text.Style;
 import javax.swing.text.StyleConstants;
 
@@ -29,26 +31,26 @@ public class ResetFontAction extends DefaultAction {
                
                /*we need to loop on every style , if not after the second change, styles will not change anymore
                  except default*/
+                       int numberOfTab = getEditor().getTabPane().getComponentCount();
+                       for ( int j = 0 ; j < numberOfTab ; j++){
+                               
+                               JTextPane textPane = (JTextPane) ((JScrollPane) getEditor().getTabPane().getComponentAt(j)).getViewport().getComponent(0) ;
                
-               for (int i = 0 ; i < listStylesName.size() ; i++ )
-               {
-                       Style tempStyle = getEditor().getTextPane().getStyledDocument().getStyle(listStylesName.get(i));
-
-               
-               StyleConstants.setFontFamily(tempStyle ,oldFont.getFamily() );
-               StyleConstants.setFontSize(tempStyle, oldFont.getSize());
-               StyleConstants.setBold(tempStyle, oldFont.isBold());
-               //StyleConstants.setItalic(tempStyle, newFont.isItalic());
-               
-
-                       
-               }
+                       for (int i = 0 ; i < listStylesName.size() ; i++ ){
+                               Style tempStyle =  textPane.getStyledDocument().getStyle(listStylesName.get(i));
                
+                       StyleConstants.setFontFamily(tempStyle ,oldFont.getFamily() );
+                       StyleConstants.setFontSize(tempStyle, oldFont.getSize());
+                       StyleConstants.setBold(tempStyle, oldFont.isBold());
+                       //StyleConstants.setItalic(tempStyle, newFont.isItalic());                      
+                       }
+                       /*insert update refresh the styles without needing to type text*/
+                       ((ScilabStyleDocument)  textPane.getStyledDocument()).insertUpdate(null);
+                       }
 
                
-               /*insert update refresh the styles without needing to type text*/
-               ((ScilabStyleDocument) getEditor().getTextPane().getStyledDocument()).insertUpdate(null);
-               getEditor().getTextPane().requestFocus();
+
+               getEditor().getTextPane().setFocusable(true);
                
                ConfigXpadManager.saveFont(oldFont);
        }
index 1072419..ac297e2 100644 (file)
@@ -26,6 +26,8 @@ import javax.swing.JButton;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
 import javax.swing.text.Style;
 import javax.swing.text.StyleConstants;
 
@@ -114,12 +116,14 @@ public class SetColorsAction extends DefaultAction {
                                _colorChooser.displayAndWait();
                                Color newColor = _colorChooser.getSelectedColor();
                                
-                               allStylesColor.put(listStylesName.get(i), newColor );
-                               
+                               if (newColor != null ){
+                                       allStylesColor.put(listStylesName.get(i), newColor );
+                                       stylesNamesLabelList.get(i).setForeground(newColor);
+                               }
                                /*update label color*/
-                               stylesNamesLabelList.get(i).setForeground(newColor);
+                               
 
-                                       frame.requestFocus();
+                                       frame.setFocusable(true);
                                }
                        };
        
@@ -192,17 +196,23 @@ public class SetColorsAction extends DefaultAction {
                        public void actionPerformed(ActionEvent e) {
                                
                                /*apply all the new colors to the editor*/
-                               for (int i = 0; i <numberOfStyles ; i++) {
+                               int numberOfTab = getEditor().getTabPane().getComponentCount();
+                               for ( int j = 0 ; j < numberOfTab ; j++){
                                        
-                                       Color thisStyleColor = allStylesColor.get(listStylesName.get(i));               
-                               Style tempStyle = getEditor().getTextPane().getStyledDocument().getStyle(listStylesName.get(i));
+                                       JTextPane textPane = (JTextPane) ((JScrollPane) getEditor().getTabPane().getComponentAt(j)).getViewport().getComponent(0) ;
 
-                               StyleConstants.setForeground (tempStyle ,thisStyleColor );                                  
+                               
+                                       for (int i = 0; i <numberOfStyles ; i++) {
+                                               
+                                               Color thisStyleColor = allStylesColor.get(listStylesName.get(i));               
+                                       Style tempStyle = textPane.getStyledDocument().getStyle(listStylesName.get(i));
        
+                                       StyleConstants.setForeground (tempStyle ,thisStyleColor );                                  
+               
+                                       }
+                                       /*without this line we would have needed to type a character to see the update*/        
+                               ((ScilabStyleDocument) textPane.getStyledDocument()).insertUpdate(null);
                                }
-                               /*without this line we would have needed to type a character to see the update*/        
-                       ((ScilabStyleDocument) getEditor().getTextPane().getStyledDocument()).insertUpdate(null);
-                               
                        /*save the change in the xml*/
                                ConfigXpadManager.saveAllForegroundColors(allStylesColor);
                                SetColorsAction.windowAlreadyExist= false ;
index a7a7ab1..7bea67a 100644 (file)
@@ -3,6 +3,8 @@ package org.scilab.modules.xpad.actions;
 import java.awt.Font;
 import java.util.ArrayList;
 
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
 import javax.swing.text.Style;
 import javax.swing.text.StyleConstants;
 
@@ -32,25 +34,26 @@ public class SetFontAction extends DefaultAction {
                
                /*we need to loop on every style , if not after the second change, styles will not change anymore
                  except default*/
-               
-               for (int i = 0 ; i < listStylesName.size() ; i++ )
-               {
-                       Style tempStyle = getEditor().getTextPane().getStyledDocument().getStyle(listStylesName.get(i));
-
-               
-               StyleConstants.setFontFamily(tempStyle ,newFont.getFamily() );
-               StyleConstants.setFontSize(tempStyle, newFont.getSize());
-               StyleConstants.setBold(tempStyle, newFont.isBold());
-               //StyleConstants.setItalic(tempStyle, newFont.isItalic());
-               
+                       int numberOfTab = getEditor().getTabPane().getComponentCount();
+                       for ( int j = 0 ; j < numberOfTab ; j++){
+                               
+                               JTextPane textPane = (JTextPane) ((JScrollPane) getEditor().getTabPane().getComponentAt(j)).getViewport().getComponent(0) ;
+                               
+                       for (int i = 0 ; i < listStylesName.size() ; i++ ){
+                               Style tempStyle = textPane.getStyledDocument().getStyle(listStylesName.get(i));
+       
+                       StyleConstants.setFontFamily(tempStyle ,newFont.getFamily() );
+                       StyleConstants.setFontSize(tempStyle, newFont.getSize());
+                       StyleConstants.setBold(tempStyle, newFont.isBold());
+                       //StyleConstants.setItalic(tempStyle, newFont.isItalic());
+       
+                       }
+                       /*insert update refresh the styles without needing to type text*/
+                       ((ScilabStyleDocument) textPane.getStyledDocument()).insertUpdate(null);
+                       }
 
-                       
-               }
                
 
-               
-               /*insert update refresh the styles without needing to type text*/
-               ((ScilabStyleDocument) getEditor().getTextPane().getStyledDocument()).insertUpdate(null);
                getEditor().getTextPane().setFocusable(true);
                
                ConfigXpadManager.saveFont(newFont);