Preferences: Begin to connect Scinotes 93/7393/5
Calixte DENIZET [Mon, 4 Jun 2012 18:31:08 +0000 (20:31 +0200)]
Change-Id: I54079a57d4174579b9f1ea6bbc5a910858cbae52

38 files changed:
scilab/modules/commons/src/java/org/scilab/modules/commons/gui/ScilabKeyStroke.java
scilab/modules/commons/src/java/org/scilab/modules/commons/xml/XConfiguration.java
scilab/modules/commons/src/java/org/scilab/modules/commons/xml/XConfigurationEvent.java [new file with mode: 0644]
scilab/modules/commons/src/java/org/scilab/modules/commons/xml/XConfigurationListener.java [new file with mode: 0644]
scilab/modules/console/Makefile.am
scilab/modules/console/Makefile.in
scilab/modules/console/etc/Actions-Configuration.xml [new file with mode: 0644]
scilab/modules/console/etc/XConfiguration-general.xml
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/colorchooser/SwingScilabColorChooser.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/SwingScilabFileChooser.java
scilab/modules/history_manager/etc/XConfiguration-history.xsl
scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/Checkbox.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/Color.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/FileSelector.java [new file with mode: 0644]
scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/FontSelector.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/Link.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/Radiobutton.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/ComponentFactory.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/XCommonManager.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/XConfigManager.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/XUpdateVisitor.java
scilab/modules/scinotes/etc/XConfiguration-scinotes.xml
scilab/modules/scinotes/etc/XConfiguration-scinotes.xsl
scilab/modules/scinotes/etc/scinotesGUIConfiguration.xml
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/MatchingBlockManager.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotes.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesConfiguration.java [new file with mode: 0644]
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesGUI.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesLineNumberPanel.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesOptions.java [new file with mode: 0644]
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabContext.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabEditorPane.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/AutoIndentAction.java [deleted file]
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/LineNumbersAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/RemoveAnchorAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/utils/NavigatorWindow.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/utils/ScilabTabbedPane.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/utils/SearchFile.java

index 5730845..ae02e7c 100644 (file)
@@ -28,19 +28,19 @@ public final class ScilabKeyStroke {
         String key = "";
         int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
         if ((mask & KeyEvent.CTRL_MASK) != 0) {
-            key += " control";
+            key += " Ctrl";
         }
         if ((mask & KeyEvent.META_MASK) != 0) {
-            key += " meta";
+            key += " Meta";
         }
         if ((mask & KeyEvent.SHIFT_MASK) != 0) {
-            key += " shift";
+            key += " Shift";
         }
         if ((mask & KeyEvent.ALT_MASK) != 0) {
-            key += " alt";
+            key += " Alt";
         }
         if ((mask & KeyEvent.ALT_GRAPH_MASK) != 0) {
-            key += " altGraph";
+            key += " AltGraph";
         }
 
         if (key.length() > 0 && key.startsWith(" ")) {
@@ -51,13 +51,21 @@ public final class ScilabKeyStroke {
     }
 
     /**
+     * Get the OS meta key: usually Ctrl for Linux or Windows OS, and Meta (Apple) for Mac OS
+     * @return the OS special meta key
+     */
+    public static final String getOSMetaKey() {
+        return oSKey;
+    }
+
+    /**
      * @param key String representation of the key "control A" or
      * "OSSCKEY A" where OSSCKEY is replaced by the default meta key of
      * the OS.
      * @return the corresponding key
      */
     public static KeyStroke getKeyStroke(String key) {
-        String str = key.replaceAll("OSSCKEY", oSKey);
+        String str = key.replaceAll("OSSCKEY", oSKey.toLowerCase());
 
         return KeyStroke.getKeyStroke(str);
     }
index 0352af4..944ebb0 100644 (file)
@@ -17,6 +17,9 @@ import java.io.File;
 import java.io.FilenameFilter;
 import java.io.FileFilter;
 import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
@@ -25,11 +28,21 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.HashSet;
+import java.util.Set;
 
 import javax.swing.KeyStroke;
+import javax.swing.event.EventListenerList;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpressionException;
@@ -43,6 +56,7 @@ import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 import org.scilab.modules.commons.ScilabCommons;
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
 
 /**
  * Class to retrieve object from the xml configuration file
@@ -58,34 +72,76 @@ public class XConfiguration {
     private static final String SCILAB_CONFIG_FILE = SCI + "/modules/preferences/etc/XConfiguration.xml";
 
     private static final String ERROR_READ = "Could not load file: ";
+    private static final String ERROR_WRITE = "Could not write the file: ";
 
     private static final XPathFactory xpathFactory = XPathFactory.newInstance();
-    private static final Map<Class<?>, StringParser> conv = new HashMap<Class<?>, StringParser>();
+    private static final Map < Class<?>, StringParser > conv = new HashMap < Class<?>, StringParser > ();
+
+    private static final EventListenerList listenerList = new EventListenerList();
+    private static final Set<String> modifiedPaths = new HashSet<String>();
+
+    private static Document doc;
 
     /**
      * Get the document in SCIHOME corresponding to the configuration file.
      * @return the configuration document.
      */
     public static Document getXConfigurationDocument() {
-        File xml = new File(USER_CONFIG_FILE);
-        if (!xml.exists()) {
-            return createDocument();
+        if (doc == null) {
+            File xml = new File(USER_CONFIG_FILE);
+            if (!xml.exists()) {
+                ScilabXMLUtilities.writeDocument(createDocument(), USER_CONFIG_FILE);
+            }
+
+            DocumentBuilder docBuilder = null;
+
+            try {
+                DocumentBuilderFactory factory = ScilabDocumentBuilderFactory.newInstance();
+                docBuilder = factory.newDocumentBuilder();
+                doc = docBuilder.parse(xml);
+                return doc;
+            } catch (ParserConfigurationException pce) {
+                System.err.println(ERROR_READ + USER_CONFIG_FILE);
+            } catch (SAXException se) {
+                System.err.println(ERROR_READ + USER_CONFIG_FILE);
+            } catch (IOException ioe) {
+                System.err.println(ERROR_READ + USER_CONFIG_FILE);
+            }
+            return null;
         }
 
-        DocumentBuilder docBuilder = null;
+        return doc;
+    }
 
+    /**
+     * Save the modifications
+     */
+    public static void writeDocument(String filename, Node written) {
+        Transformer transformer = null;
         try {
-            DocumentBuilderFactory factory = ScilabDocumentBuilderFactory.newInstance();
-            docBuilder = factory.newDocumentBuilder();
-            return docBuilder.parse(xml);
-        } catch (ParserConfigurationException pce) {
-            System.err.println(ERROR_READ + USER_CONFIG_FILE);
-        } catch (SAXException se) {
-            System.err.println(ERROR_READ + USER_CONFIG_FILE);
-        } catch (IOException ioe) {
-            System.err.println(ERROR_READ + USER_CONFIG_FILE);
+            transformer = ScilabTransformerFactory.newInstance().newTransformer();
+        } catch (TransformerConfigurationException e1) {
+            System.err.println(ERROR_WRITE + filename);
+            return;
+        } catch (TransformerFactoryConfigurationError e1) {
+            System.err.println(ERROR_WRITE + filename);
+            return;
+        }
+        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+
+        StreamResult result = new StreamResult(new File(filename));
+        DOMSource source = new DOMSource(written);
+        try {
+            transformer.transform(source, result);
+        } catch (TransformerException e) {
+            System.err.println(ERROR_WRITE + filename);
+            return;
+        }
+
+        // Invalidate the current document
+        if (filename.equals(USER_CONFIG_FILE)) {
+            doc = null;
         }
-        return null;
     }
 
     /**
@@ -117,13 +173,25 @@ public class XConfiguration {
         List<File> etcs = getEtcDir();
         for (File etc : etcs) {
             File[] xmls = etc.listFiles(new FilenameFilter() {
-                    public boolean accept(File dir, String name) {
-                        return name.endsWith(".xml") && name.startsWith("XConfiguration-");
-                    }
-                });
+                public boolean accept(File dir, String name) {
+                    return name.endsWith(".xml") && name.startsWith("XConfiguration-");
+                }
+            });
             for (File xml : xmls) {
                 try {
                     Document doc = docBuilder.parse(xml);
+                    if (xml.getName().equals("XConfiguration-general.xml")) {
+                        try {
+                            XPath xp = xpathFactory.newXPath();
+                            NodeList nodes = (NodeList) xp.compile("//shortcuts/body/actions/action-folder/action[contains(@key, 'OSSCKEY')]").evaluate(doc, XPathConstants.NODESET);
+                            for (int i = 0; i < nodes.getLength(); i++) {
+                                Element e = (Element) nodes.item(i);
+                                e.setAttribute("key", e.getAttribute("key").replace("OSSCKEY", ScilabKeyStroke.getOSMetaKey()));
+                            }
+                        } catch (XPathExpressionException e) {
+                            System.err.println(e);
+                        }
+                    }
                     Node node = mainDoc.importNode(doc.getDocumentElement(), true);
                     NodeList list = root.getElementsByTagName(node.getNodeName());
                     if (list.getLength() != 0) {
@@ -143,15 +211,15 @@ public class XConfiguration {
     /**
      * Get a the list of the etc dirs in modules dirs
      * @return the lit of etc dirs
-     */ 
+     */
     public static List<File> getEtcDir() {
         List<File> list = new ArrayList<File>();
         File modulesDir = new File(SCI + "/modules/");
         File[] modules = modulesDir.listFiles(new FileFilter() {
-                public boolean accept(File f) {
-                    return f.isDirectory();
-                }
-            });
+            public boolean accept(File f) {
+                return f.isDirectory();
+            }
+        });
 
         for (File module : modules) {
             File etc = new File(module, "/etc/");
@@ -163,6 +231,44 @@ public class XConfiguration {
         return list;
     }
 
+    public static void addModifiedPath(String path) {
+        if (path != null && !path.isEmpty()) {
+            modifiedPaths.add(path);
+        }
+    }
+
+    public static void clearModifiedPath() {
+        modifiedPaths.clear();
+    }
+
+    public static void addXConfigurationListener(XConfigurationListener listener) {
+        listenerList.add(XConfigurationListener.class, listener);
+    }
+
+    public static void removeXConfigurationListener(XConfigurationListener listener) {
+        listenerList.remove(XConfigurationListener.class, listener);
+    }
+
+    public static XConfigurationListener[] getXConfigurationListeners() {
+        return listenerList.getListeners(XConfigurationListener.class);
+    }
+
+    public static void fireXConfigurationEvent() {
+        XConfigurationEvent event = null;
+        Object[] listeners = listenerList.getListenerList();
+        for (int i = listeners.length - 2; i >= 0; i -= 2) {
+            if (listeners[i] == XConfigurationListener.class) {
+                if (event == null) {
+                    event = new XConfigurationEvent(modifiedPaths);
+                }
+
+                ((XConfigurationListener) listeners[i + 1]).configurationChanged(event);
+            }
+        }
+
+        modifiedPaths.clear();
+    }
+
     /**
      * Register a StringParser for a given Class
      * @param type the class type
@@ -181,6 +287,26 @@ public class XConfiguration {
         return conv.get(type);
     }
 
+    public static void set(final Document doc, final String path, String value) {
+        XPath xp = xpathFactory.newXPath();
+        NodeList nodes;
+        try {
+            nodes = (NodeList) xp.compile(path).evaluate(doc, XPathConstants.NODESET);
+        } catch (XPathExpressionException e) {
+            System.err.println(e);
+            return;
+        }
+
+        for (int i = 0; i < nodes.getLength() ; i++) {
+            Node n = nodes.item(i);
+            if (n != null && n.getNodeType() == Node.ATTRIBUTE_NODE) {
+                n.setNodeValue(value);
+            }
+        }
+
+        writeDocument(USER_CONFIG_FILE, doc);
+    }
+
     /**
      * Get all the nodes with the given path.
      * All the get nodes are serialized into an object (generic paramater) which must have
@@ -210,6 +336,26 @@ public class XConfiguration {
      * </code>
      * If an attribute must not be retrieved, just remove the setter.
      *
+     * It is possible to use the annotation @XConfAttribute to make easier the retrievement.
+     * For example
+     * <code>
+     * @XConfAttribute
+     * public class MyObject {
+     *
+     *    public MyObject() {
+     *       // ...
+     *    }
+     *
+     *    @XConfAttribute(attributes={"aaa", "bbb", "ccc-ddd"})
+     *    // the contents of aaa will be converted into int and passed as first argument
+     *    // the contents of bbb will be converted into boolean and passed as second argument
+     *    // the contents of ccc-ddd will be converted into Color and passed as third argument
+     *    public void set(int n, boolean b, Color c) {
+     *       // ...
+     *    }
+     *  }
+     * </code>
+     *
      * @param type the Class type to retrieve
      * @param doc the document to explore
      * @param path the xpath query to retrieve the corresponding nodeset.
@@ -225,13 +371,20 @@ public class XConfiguration {
             return (T[]) Array.newInstance(type, 0);
         }
 
-        Method[] meths = type.getMethods();
+        if (type.getAnnotation(XConfAttribute.class) != null) {
+            T[] arr = get(type, nodes);
+            if (arr != null) {
+                return arr;
+            }
+        }
+
+        Method[] meths = type.getDeclaredMethods();
         Map<String, Method> mapMethods = new HashMap<String, Method>();
         for (Method m : meths) {
-            m.setAccessible(true);
             String name = m.getName();
             if (name.startsWith("set") && m.getParameterTypes().length == 1 && m.getReturnType().equals(Void.TYPE)) {
                 mapMethods.put(m.getName(), m);
+                m.setAccessible(true);
             }
         }
 
@@ -241,7 +394,7 @@ public class XConfiguration {
         for (int i = 0; i < values.length; i++) {
             NamedNodeMap map = nodes.item(i).getAttributes();
             try {
-                Constructor<T> constructor = type.getConstructor(new Class[]{});
+                Constructor<T> constructor = type.getDeclaredConstructor(new Class[] {});
                 constructor.setAccessible(true);
                 values[i] = constructor.newInstance();
             } catch (InstantiationException e) {
@@ -258,7 +411,7 @@ public class XConfiguration {
             }
 
             for (int j = 0; j < map.getLength(); j++) {
-                Node n =  map.item(j);
+                Node n = map.item(j);
                 String name = n.getNodeName();
                 String methName = names.get(name);
                 if (methName == null) {
@@ -266,7 +419,7 @@ public class XConfiguration {
                     String[] parts = name.split("-");
                     for (String part : parts) {
                         if (part != null && part.length() > 0) {
-                            buffer.append(part.substring(0,1).toUpperCase());
+                            buffer.append(part.substring(0, 1).toUpperCase());
                             buffer.append(part.substring(1).toLowerCase());
                         }
                     }
@@ -279,7 +432,7 @@ public class XConfiguration {
                     Class[] paramsClass = method.getParameterTypes();
                     StringParser parser = conv.get(paramsClass[0]);
                     if (parser != null) {
-                        Object[] params = new Object[]{parser.parse(value)};
+                        Object[] params = new Object[] {parser.parse(value)};
                         try {
                             method.invoke(values[i], params);
                         } catch (IllegalAccessException e) {
@@ -298,6 +451,158 @@ public class XConfiguration {
     }
 
     /**
+     * Get a Map with where the key is the converted value (according to keyType) of the attribute named key
+     * and the value is given in the same way.
+     * @param doc the document to read
+     * @param key the attribute name where its value will be converted and used as a key in the map
+     * @param keyType the Class of the key
+     * @param value the attribute name where its value will be converted and used as a value in the map
+     * @param valueType the Class of the value
+     * @return the corresponding map.
+     */
+    public static final <T, U> Map<T, U> get(final Document doc, final String key, final Class<T> keyType, final String value, final Class<U> valueType, final String path) {
+        XPath xp = xpathFactory.newXPath();
+        Map<T, U> map = new HashMap<T, U>();
+        NodeList nodes;
+        try {
+            nodes = (NodeList) xp.compile(path).evaluate(doc, XPathConstants.NODESET);
+        } catch (XPathExpressionException e) {
+            System.err.println(e);
+            return map;
+        }
+
+        int len = nodes.getLength();
+        for (int i = 0; i < len; i++) {
+            NamedNodeMap nmap = nodes.item(i).getAttributes();
+            Node k = nmap.getNamedItem(key);
+            Node v = nmap.getNamedItem(value);
+            if (k == null || v == null) {
+                return map;
+            }
+
+            String kk = k.getNodeValue();
+            String vv = v.getNodeValue();
+
+            StringParser convK = conv.get(keyType);
+            StringParser convV = conv.get(valueType);
+            if (convK == null || convV == null) {
+                return map;
+            }
+
+            map.put((T) convK.parse(kk), (U) convV.parse(vv));
+        }
+
+        return map;
+    }
+
+    /**
+     * Getter for annoted class (with @XConfAttribute)
+     * @param type the class type
+     * @param nodes the nodes to read
+     * @return an array of instances of type, if the class is annoted with @XConfAttribute(isStatic=true),
+     * the returned array is empty.
+     */
+    private static final <T> T[] get(final Class<T> type, NodeList nodes) {
+        Method[] meths = type.getDeclaredMethods();
+        List<String[]> attrs = new ArrayList<String[]>();
+        List<Method> methods = new ArrayList<Method>();
+        Map<String[], Method> mapMethods = new HashMap<String[], Method>();
+        for (Method m : meths) {
+            String name = m.getName();
+            Annotation ann = m.getAnnotation(XConfAttribute.class);
+            if (ann != null) {
+                String[] attributes = ((XConfAttribute) ann).attributes();
+                if (attributes.length == m.getParameterTypes().length) {
+                    m.setAccessible(true);
+                    attrs.add(attributes);
+                    methods.add(m);
+                } else {
+                    return null;
+                }
+            }
+        }
+
+        Annotation ann = type.getAnnotation(XConfAttribute.class);
+        boolean mustInstantiate = !((XConfAttribute) ann).isStatic();
+
+        T[] values = null;
+        int len = nodes.getLength();
+        if (mustInstantiate) {
+            values = (T[]) Array.newInstance(type, len);
+        }
+
+        for (int i = 0; i < len; i++) {
+            NamedNodeMap map = nodes.item(i).getAttributes();
+            String nodeName = nodes.item(i).getNodeName();
+
+            if (mustInstantiate) {
+                try {
+                    Constructor<T> constructor = type.getDeclaredConstructor(new Class[] {});
+                    constructor.setAccessible(true);
+                    values[i] = constructor.newInstance();
+                } catch (InstantiationException e) {
+                    System.err.println(e);
+                    break;
+                } catch (IllegalAccessException e) {
+                    System.err.println(e);
+                    break;
+                } catch (NoSuchMethodException e) {
+                    System.err.println(e);
+                    break;
+                } catch (InvocationTargetException e) {
+                    System.err.println(e.getTargetException());
+                }
+            }
+
+            for (int j = 0; j < methods.size(); j++) {
+                Method method = methods.get(j);
+                ann = method.getAnnotation(XConfAttribute.class);
+                String tag = ((XConfAttribute) ann).tag();
+                if (tag.isEmpty() || tag.equals(nodeName)) {
+                    String[] attributes = attrs.get(j);
+                    Object[] params = new Object[attributes.length];
+                    Class[] paramsClass = method.getParameterTypes();
+                    for (int k = 0; k < attributes.length; k++) {
+                        String p = "";
+                        Node node = null;
+                        if (map != null) {
+                            node = map.getNamedItem(attributes[k]);
+                        }
+                        if (node != null) {
+                            p = node.getNodeValue();
+                        }
+
+                        StringParser parser = conv.get(paramsClass[k]);
+                        if (parser != null) {
+                            params[k] = parser.parse(p);
+                        }
+                    }
+
+                    try {
+                        if (mustInstantiate) {
+                            method.invoke(values[i], params);
+                        } else {
+                            method.invoke(null, params);
+                        }
+                    } catch (IllegalAccessException e) {
+                        System.err.println(e);
+                    } catch (IllegalArgumentException e) {
+                        System.err.println(e);
+                    } catch (InvocationTargetException e) {
+                        System.err.println(e.getTargetException());
+                    }
+                }
+            }
+        }
+
+        if (mustInstantiate) {
+            return values;
+        } else {
+            return (T[]) Array.newInstance(type, 0);
+        }
+    }
+
+    /**
      * Interface to implement to parse an attribute String into a Java object
      */
     public static interface StringParser {
@@ -312,14 +617,14 @@ public class XConfiguration {
 
     static {
         conv.put(int.class, new StringParser() {
-            public Object parse(String str) {
+            public Integer parse(String str) {
                 try {
                     return Integer.parseInt(str);
                 } catch (NumberFormatException e) {
                     try {
                         return (int) Double.parseDouble(str);
                     } catch (NumberFormatException ee) {
-                        return null;
+                        return new Integer(0);
                     }
                 }
             }
@@ -329,7 +634,7 @@ public class XConfiguration {
                 if (str.length() > 0) {
                     return str.charAt(0);
                 } else {
-                    return null;
+                    return new Character((char) 0);
                 }
             }
         });
@@ -341,7 +646,7 @@ public class XConfiguration {
                     try {
                         return (byte) Double.parseDouble(str);
                     } catch (NumberFormatException ee) {
-                        return null;
+                        return new Byte((byte) 0);
                     }
                 }
             }
@@ -354,7 +659,7 @@ public class XConfiguration {
                     try {
                         return (short) Double.parseDouble(str);
                     } catch (NumberFormatException ee) {
-                        return null;
+                        return new Short((short) 0);
                     }
                 }
             }
@@ -364,7 +669,7 @@ public class XConfiguration {
                 try {
                     return Double.parseDouble(str);
                 } catch (NumberFormatException ee) {
-                    return null;
+                    return new Double((double) 0);
                 }
             }
         });
@@ -373,7 +678,7 @@ public class XConfiguration {
                 try {
                     return Float.parseFloat(str);
                 } catch (NumberFormatException ee) {
-                    return null;
+                    return new Float((float) 0);
                 }
             }
         });
@@ -390,7 +695,7 @@ public class XConfiguration {
                     try {
                         return (long) Double.parseDouble(str);
                     } catch (NumberFormatException ee) {
-                        return null;
+                        return new Long((long) 0);
                     }
                 }
             }
@@ -405,14 +710,43 @@ public class XConfiguration {
                 try {
                     return Color.decode(str);
                 } catch (NumberFormatException e) {
-                    return null;
+                    return Color.BLACK;
                 }
             }
         });
         conv.put(KeyStroke.class, new StringParser() {
             public Object parse(String str) {
-                return KeyStroke.getKeyStroke(str);
+                String[] toks = str.split(" +");
+                StringBuilder buffer = new StringBuilder();
+                for (int i = 0; i < toks.length - 1; i++) {
+                    buffer.append(toks[i].toLowerCase());
+                    buffer.append(" ");
+                }
+                buffer.append(toks[toks.length - 1].toUpperCase());
+                return KeyStroke.getKeyStroke(buffer.toString());
             }
         });
     }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface XConfAttribute {
+
+        /**
+         * Map method arguments with attributes name
+         * For example,
+         * <code>
+         * @XConfAttribute(tag="mytag", attributes={"a", "b"})
+         * void foo(String one, int tow) { ... }
+         * </code>
+         * The value of attribute "a" is converted into a String and passed as "one" argument,...
+         */
+    public String[] attributes() default {""};
+
+    public String tag() default "";
+
+        /**
+         * Used to avoid object instanciation so the differents annotated methods must be static.
+         */
+    public boolean isStatic() default false;
+    }
 }
diff --git a/scilab/modules/commons/src/java/org/scilab/modules/commons/xml/XConfigurationEvent.java b/scilab/modules/commons/src/java/org/scilab/modules/commons/xml/XConfigurationEvent.java
new file mode 100644 (file)
index 0000000..abe96d5
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.commons.xml;
+
+import java.util.Set;
+
+public class XConfigurationEvent {
+
+    private Set<String> changedPaths;
+
+    /**
+     * Default constructor
+     * @param changedPaths a set containing all the paths which have been modified
+     */
+    public XConfigurationEvent(Set<String> changedPaths) {
+        this.changedPaths = changedPaths;
+    }
+
+    /**
+     * Get the modified paths
+     * @return the modified paths as a set
+     */
+    public Set<String> getModifiedPaths() {
+        return changedPaths;
+    }
+}
\ No newline at end of file
diff --git a/scilab/modules/commons/src/java/org/scilab/modules/commons/xml/XConfigurationListener.java b/scilab/modules/commons/src/java/org/scilab/modules/commons/xml/XConfigurationListener.java
new file mode 100644 (file)
index 0000000..bbbd788
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.commons.xml;
+
+import java.util.EventListener;
+
+public interface XConfigurationListener extends EventListener {
+
+    /**
+     * Prevent the listener that configuration has changed
+     *
+     * @param e the event
+     */
+    public void configurationChanged(XConfigurationEvent e);
+
+}
index c1fd0be..a7acf56 100644 (file)
@@ -30,7 +30,8 @@ libsciconsole_la_etc_DATA = \
        etc/XConfiguration-console.xml \
        etc/XConfiguration-console.xsl \
        etc/XConfiguration-general.xml \
-       etc/XConfiguration-general.xsl
+       etc/XConfiguration-general.xsl \
+       etc/Actions-Configuration.xml
 
 #### console : List of the cpp files ####
 CONSOLE_CXX_JNI_SOURCES = src/jni/CallScilabBridge.cpp
index 4f0c612..746abc4 100644 (file)
@@ -543,7 +543,8 @@ libsciconsole_la_etc_DATA = \
        etc/XConfiguration-console.xml \
        etc/XConfiguration-console.xsl \
        etc/XConfiguration-general.xml \
-       etc/XConfiguration-general.xsl
+       etc/XConfiguration-general.xsl \
+       etc/Actions-Configuration.xml
 
 
 #### console : List of the cpp files ####
diff --git a/scilab/modules/console/etc/Actions-Configuration.xml b/scilab/modules/console/etc/Actions-Configuration.xml
new file mode 100644 (file)
index 0000000..190b9ac
--- /dev/null
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Map between action names and Java or Scilab action -->
+<map>
+  <scinotes>
+    <entry type="java" action="ActivateHelpOnTypingForOpenersAction" name="scinotes-autocomplete-openers"/>
+    <entry type="java" action="ActivateHelpOnTypingForKeywordsAction" name="scinotes-autocomplete-keyword"/>
+    <entry type="java" action="GenerateHelpFromFunctionAction" name="scinotes-help-prototype"/>
+    <entry type="java" action="TabifyAction" name="scinotes-tabify"/>
+    <entry type="java" action="UnTabifyAction" name="scinotes-untabify"/>
+    <entry type="java" action="IndentAction" name="scinotes-indent"/>
+    <entry type="java" action="CommentAction" name="scinotes-comment"/>
+    <entry type="java" action="UnCommentAction" name="scinotes-uncomment"/>
+    <entry type="java" action="RemoveTrailingWhiteAction" name="scinotes-remove-whites"/>
+    <entry type="java" action="SelectAllAction" name="scinotes-select-all"/>
+    <entry type="java" action="SelectBlockAction" name="scinotes-select-block"/>
+    <entry type="java" action="OpenTabInNewWindowAction" name="scinotes-clone-current"/>
+    <entry type="java" action="CCloseTabInNewWindowAction" name="scinotes-export-current"/>
+    <entry type="java" action="CopyAsHTMLAction" name="scinotes-copy"/>
+    <entry type="java" action="CutAction" name="scinotes-cut"/>
+    <entry type="java" action="PasteAction" name="scinotes-paste"/>
+    <entry type="java" action="PasteColumnAction" name="scinotes-paste-column"/>
+    <entry type="java" action="RepeatSelectionOnColumnAction" name="scinotes-repeat-column"/>
+    <entry type="java" action="UndoAction" name="scinotes-undo"/>
+    <entry type="java" action="RedoAction" name="scinotes-redo"/>
+    <entry type="java" action="CopyAsHTMLWithLineNumberAction" name="scinotes-copy-with-lines"/>
+    <entry type="java" action="NewAction" name="scinotes-new"/>
+    <entry type="java" action="OpenAction" name="scinotes-open"/>
+    <entry type="java" action="OpenURLAction" name="scinotes-open-url"/>
+    <entry type="java" action="OpenSourceFileOnKeywordAction" name="scinotes-open-source"/>
+    <entry type="java" action="SaveAction" name="scinotes-save"/>
+    <entry type="java" action="SaveAsAction" name="scinotes-save-as"/>
+    <entry type="java" action="ReloadAction" name="scinotes-reload"/>
+    <entry type="java" action="PrintPreviewAction" name="scinotes-print-preview"/>
+    <entry type="java" action="PrintAction" name="scinotes-print"/>
+    <entry type="java" action="CloseAction" name="scinotes-close"/>
+    <entry type="java" action="ExitAction" name="scinotes-exit"/>
+    <entry type="java" action="ToLowerCaseAction" name="scinotes-tolowercase"/>
+    <entry type="java" action="ToUpperCaseAction" name="scinotes-touppercase"/>
+    <entry type="java" action="CapitalizeAction" name="scinotes-capitalize"/>
+    <entry type="java" action="HelpOnKeywordAction" name="scinotes-help-keyword"/>
+    <entry type="java" action="LoadIntoScilabAction" name="scinotes-load-scilab"/>
+    <entry type="java" action="ExecuteFileIntoScilabAction" name="scinotes-execute-scilab"/>
+    <entry type="java" action="EvaluateSelectionAction" name="scinotes-evaluate-selection"/>
+    <entry type="java" action="SaveAndExecuteFileAction" name="scinotes-save-execute"/>
+    <entry type="java" action="SaveAndExecuteAllFilesAction" name="scinotes-save-execute-all"/>
+    <entry type="java" action="FindAction" name="scinotes-find"/>
+    <entry type="java" action="FindNextAction" name="scinotes-find-next"/>
+    <entry type="java" action="FindPreviousAction" name="scinotes-find-previous"/>
+    <entry type="java" action="IncrementalSearchAction" name="scinotes-incremental-search"/>
+    <entry type="java" action="SetAnchorAction" name="scinotes-set-anchor"/>
+    <entry type="java" action="RemoveAnchorAction" name="scinotes-remove-anchor"/>
+    <entry type="java" action="GotoNextAnchorAction" name="scinotes-next-anchor"/>
+    <entry type="java" action="GotoPreviousAnchorAction" name="scinotes-previous-anchor"/>
+    <entry type="java" action="CodeNavigatorAction" name="scinotes-code-navigator"/>
+    <entry type="java" action="SearchWordInFilesAction" name="scinotes-word-file"/>
+    <entry type="java" action="SearchFilesAction" name="scinotes-search-files"/>
+    <entry type="java" action="SciNotesCompletionAction" name="scinotes-completion"/>
+    <entry type="java" action="HelpAction" name="scinotes-help"/>
+    <entry type="java" action="AboutAction" name="scinotes-about"/>
+    <entry type="java" action="NextTabAction" name="scinotes-next-tab"/>
+    <entry type="java" action="PreviousTabAction" name="scinotes-previous-tab"/>
+    <entry type="java" action="DeleteAction" name="scinotes-delete"/>
+    <entry type="java" action="NextParagraphAction" name="scinotes-next-paragraph"/>
+    <entry type="java" action="PreviousParagraphAction" name="scinotes-previous-paragraph"/>
+    <entry type="java" action="SaveAllAction" name="scinotes-save-all"/>
+    <entry type="java" action="OverwriteAction" name="scinotes-overwrite"/>
+    <entry type="java" action="PageSetupAction" name="scinotes-page-setup"/>
+    <entry type="java" action="CloseAllAction" name="scinotes-close-all"/>
+    <entry type="java" action="CloseAllButThisAction" name="scinotes-close-all-but"/>
+    <entry type="java" action="DoubleQuoteStringAction" name="scinotes-double-quote"/>
+    <entry type="java" action="LineNumbersAction" name="scinotes-line-numbering"/>
+    <entry type="java" action="RecentFileAction" name="scinotes-recent"/>
+    <entry type="java" action="RegisterFavoriteDirsAction" name="scinotes-register-favorite-dir"/>
+    <entry type="java" action="OpenFileInAction" name="scinotes-open-file-in"/>
+    <entry type="java" action="SaveFileInAction" name="scinotes-save-file-in"/>
+    <entry type="java" action="RestoreOpenedFilesAction" name="scinotes-restore-startup"/>
+    <entry type="java" action="ExportAction" name="scinotes-export"/>
+    <entry type="java" action="EncodingAction" name="scinotes-encoding"/>
+    <entry type="java" action="DefaultEncodingAction" name="scinotes-default-encoding"/>
+    <entry type="java" action="EndOfLineAction" name="scinotes-eof"/>
+    <entry type="java" action="CopySelectionInNewTabAction" name="scinotes-selection-new-tab"/>
+    <entry type="java" action="SplitAction" name="scinotes-split"/>
+    <entry type="java" action="HelpOnKeywordInPopupAction" name="scinotes-help-keyword-popup"/>
+  </scinotes>
+</map>
index e4123ce..87d9ead 100644 (file)
     <body>
       <actions active="scilab" name="Console" item="1" browse="--choose a file --" filter="">
         <action-folder name="Console">
-          <action key="Ctrl+E" description="Execute" name="console-execute"/>
-          <action key="Ctrl+O" description="Open a file" name="console-open"/>
-          <action key="Ctrl+L" description="Load environment" name="console-load"/>
-         <action key="Ctrl+S" description="Save environment" name="console-save"/>
-         <action key="" description="Change current directory" name="console-change-cwd"/>
-         <action key="" description="Display current directory" name="console-display-cwd"/>
-         <action key="" description="Page setup" name="console-page-setup"/>
-         <action key="Ctrl+P" description="Print" name="console-print"/>
-         <action key="Ctrl+Q" description="Quit" name="console-quit"/>
-         <action key="Ctrl+X" description="Edit" name="console-edit"/>
-         <action key="Ctrl+C" description="Copy" name="console-copy"/>
-         <action key="Ctrl+V" description="Paste" name="console-paste"/>
-         <action key="" description="Empty clipboard" name="console-empty-clipboard"/>
-         <action key="Ctrl+A" description="Select all" name="console-select-all"/>
-         <action key="" description="Preferences" name="console-prefs"/>
-         <action key="" description="Show/Hide toolbar" name="console-sh-toolbar"/>
-         <action key="" description="Clear history" name="console-clear-history"/>
-         <action key="" description="Clear console" name="console-clear"/>
-         <action key="" description="Resume" name="console-resume"/>
-         <action key="" description="Abort" name="console-abort"/>
-         <action key="" description="Interrupt" name="console-interrupt"/>
-         <action key="" description="Launch SciNotes" name="console-scinotes"/>
-         <action key="" description="Launch Xcos" name="console-xcos"/>
-         <action key="" description="Matlab to Scilab Translator" name="console-matsci-translator"/>
-         <action key="" description="Module manager" name="console-atoms"/>
-         <action key="" description="Variable Browser" name="console-variable-browser"/>
-         <action key="" description="Command History" name="console-history-browser"/>
-         <action key="" description="File Browser" name="console-file-browser"/>
-         <action key="F1" description="Help Browser" name="console-help-browser"/>
-         <action key="" description="Demonstrations" name="console-demos"/>
-         <action key="" description="Open Scilab website" name="console-scilab-website"/>
-         <action key="" description="Open Online Help" name="console-help-website"/>
-         <action key="" description="Open Scilab wiki" name="console-wiki-website"/>
-         <action key="" description="Open ATOM website" name="console-atom-website"/>
-         <action key="" description="Open File Exchange website" name="console-fileex-website"/>
-         <action key="" description="Open Mailing lists" name="console-ml-website"/>
-         <action key="" description="Open Forge website" name="console-forge-website"/>
-         <action key="" description="Open Bugzilla" name="console-bugzilla-website"/>
-         <action key="Shift+F1" description="About Scilab" name="console-about"/>
+          <action key="OSSCKEY E" description="Execute" name="console-execute"/>
+          <action key="OSSCKEY O" description="Open a file" name="console-open"/>
+          <action key="OSSCKEY L" description="Load environment" name="console-load"/>
+          <action key="OSSCKEY S" description="Save environment" name="console-save"/>
+          <action key="" description="Change current directory" name="console-change-cwd"/>
+          <action key="" description="Display current directory" name="console-display-cwd"/>
+          <action key="" description="Page setup" name="console-page-setup"/>
+          <action key="OSSCKEY P" description="Print" name="console-print"/>
+          <action key="OSSCKEY Q" description="Quit" name="console-quit"/>
+          <action key="OSSCKEY X" description="Edit" name="console-edit"/>
+          <action key="OSSCKEY C" description="Copy" name="console-copy"/>
+          <action key="OSSCKEY V" description="Paste" name="console-paste"/>
+          <action key="" description="Empty clipboard" name="console-empty-clipboard"/>
+          <action key="OSSCKEY A" description="Select all" name="console-select-all"/>
+          <action key="" description="Preferences" name="console-prefs"/>
+          <action key="" description="Show/Hide toolbar" name="console-sh-toolbar"/>
+          <action key="" description="Clear history" name="console-clear-history"/>
+          <action key="" description="Clear console" name="console-clear"/>
+          <action key="" description="Resume" name="console-resume"/>
+          <action key="" description="Abort" name="console-abort"/>
+          <action key="" description="Interrupt" name="console-interrupt"/>
+          <action key="" description="Launch SciNotes" name="console-scinotes"/>
+          <action key="" description="Launch Xcos" name="console-xcos"/>
+          <action key="" description="Matlab to Scilab Translator" name="console-matsci-translator"/>
+          <action key="" description="Module manager" name="console-atoms"/>
+          <action key="" description="Variable Browser" name="console-variable-browser"/>
+          <action key="" description="Command History" name="console-history-browser"/>
+          <action key="" description="File Browser" name="console-file-browser"/>
+          <action key="F1" description="Help Browser" name="console-help-browser"/>
+          <action key="" description="Demonstrations" name="console-demos"/>
+          <action key="" description="Open Scilab website" name="console-scilab-website"/>
+          <action key="" description="Open Online Help" name="console-help-website"/>
+          <action key="" description="Open Scilab wiki" name="console-wiki-website"/>
+          <action key="" description="Open ATOM website" name="console-atom-website"/>
+          <action key="" description="Open File Exchange website" name="console-fileex-website"/>
+          <action key="" description="Open Mailing lists" name="console-ml-website"/>
+          <action key="" description="Open Forge website" name="console-forge-website"/>
+          <action key="" description="Open Bugzilla" name="console-bugzilla-website"/>
+          <action key="Shift F1" description="About Scilab" name="console-about"/>
         </action-folder>
         <action-folder name="Scinotes">
-         <action key="Ctrl+H" description="Auto complete (, [,..." name="scinotes-autocomplete-openers"/>
-         <action key="Ctrl+Shift+H" description="Auto complete keyword" name="scinotes-autocomplete-keyword"/>
-         <action key="Ctrl+Shift+G" description="Generate Help prototype" name="scinotes-help-prototype"/>
-         <action key="TAB" description="Tabify" name="scinotes-tabify"/>
-         <action key="Shift+TAB" description="Untabify" name="scinotes-untabify"/>
-         <action key="Ctrl+I" description="Indent" name="scinotes-indent"/>
-         <action key="Ctrl+D" description="Comment" name="scinotes-comment"/>
-         <action key="Ctrl+Shift+D" description="Uncomment" name="scinotes-uncomment"/>
-         <action key="Ctrl+Shift+W" description="Remove trailing whites" name="scinotes-remove-whites"/>
-         <action key="Ctrl+A" description="Select all" name="scinotes-select-all"/>
-         <action key="Ctrl+B" description="Select block" name="scinotes-select-block"/>
-         <action key="Ctrl+Shift+T" description="Open current tab in a new window" name="scinotes-clone-current"/>
-         <action key="Ctrl+Shiftf+X" description="Export current tab in a new window" name="scinotes-export-current"/>
-         <action key="Ctrl+C" description="Copy" name="scinotes-copy"/>
-         <action key="Ctrl+X" description="Cut" name="scinotes-cut"/>
-         <action key="Ctrl+V" description="Paste" name="scinotes-paste"/>
-         <action key="Ctrl+Shift+V" description="Paste a column" name="scinotes-paste-column"/>
-         <action key="Ctrl+Shift+Z" description="Repeat selection on column" name="scinotes-repeat-column"/>
-         <action key="Ctrl+Z" description="Undo" name="scinotes-undo"/>
-         <action key="Ctrl+Y" description="Redo" name="scinotes-redo"/>
-         <action key="Ctrl+Shift+C" description="Copy as HTML with line number" name="scinotes-copy-with-lines"/>
-         <action key="Ctrl+N" description="New" name="scinotes-new"/>
-         <action key="Ctrl+O" description="Open" name="scinotes-open"/>
-         <action key="Ctrl+U" description="Open URL" name="scinotes-open-url"/>
-         <action key="Ctrl+Shift+O" description="Open source" name="scinotes-open-source"/>
-         <action key="Ctrl+S" description="Save" name="scinotes-save"/>
-         <action key="Ctrl+Shift+S" description="Save as" name="scinotes-save-as"/>
-         <action key="Ctrl+Shift+R" description="Reload" name="scinotes-reload"/>
-         <action key="Ctrl+Shift+P" description="Print preview" name="scinotes-print-preview"/>
-         <action key="Ctrl+P" description="Print" name="scinotes-print"/>
-         <action key="Ctrl+W" description="Close" name="scinotes-close"/>
-         <action key="Ctrl+Q" description="Exit" name="scinotes-exit"/>
-         <action key="Ctrl+J" description="To lower case" name="scinotes-tolowercase"/>
-         <action key="Ctrl+Shiftf+J" description="To upper case" name="scinotes-touppercase"/>
-         <action key="Ctrl+Shift+A" description="Capitalize" name="scinotes-capitalize"/>
-         <action key="Ctrl+F1" description="Help on keyword" name="scinotes-help-keyword"/>
-         <action key="Ctrl+L" description="Load in Scilab" name="scinotes-load-scilab"/>
-         <action key="Ctrl+Shift+E" description="Execute in Scilab" name="scinotes-execute-scilab"/>
-         <action key="Ctrl+E" description="Evalute selection" name="scinotes-evaluate"/>
-         <action key="F5" description="Save and execute" name="scinotes-save-execute"/>
-         <action key="Ctrl+F5" description="Save and execute all" name="scinotes-save-execute-all"/>
-         <action key="Ctrl+F" description="Find" name="scinotes-find"/>
-         <action key="Ctrl+K" description="Find next" name="scinotes-find-next"/>
-         <action key="Ctrl+Shift+K" description="Find previous" name="scinotes-find-previous"/>
-         <action key="F3" description="Incremental search" name="scinotes-incremental-search"/>
-         <action key="Ctrl+M" description="Set anchor" name="scinotes-set-anchor"/>
-         <action key="Ctrl+Shift+M" description="Remove anchor" name="scinotes-remove-anchor"/>
-         <action key="Ctrl+Shift+LESS" description="Go to next anchor" name="scinotes-next-anchor"/>
-         <action key="Ctrl+LESS" description="Go to previous anchor" name="scinotes-previous-anchor"/>
-         <action key="Ctrl+G" description="Start Code Navigator" name="scinotes-code-navigator"/>
-         <action key="Ctrl+Shift+F" description="Search word in file" name="scinotes-word-file"/>
-         <action key="Ctrl+Shift+B" description="Search files" name="scinotes-search-files"/>
-         <action key="Ctrl+SPACE" description="Keyword cmppletion" name="scinotes-completion"/>
-         <action key="F1" description="Help" name="scinotes-help"/>
-         <action key="Shift+F1" description="About" name="scinotes-about"/>
-         <action key="Ctrl+PAGE_DOWN" description="Next tab" name="scinotes-next-tab"/>
-         <action key="Ctrl+PAGE_UP" description="Previous tab" name="scinotes-previous-tab"/>
-         <action key="DELETE" description="Delete" name="scinotes-delete"/>
-         <action key="Ctrl+DOWN" description="Next paragraph" name="scinotes-next-paragraph"/>
-         <action key="Ctrl+UP" description="Previous paragraph" name="scinotes-previous-paragraph"/>
-         <action key="" description="Save all" name="scinotes-save-all"/>
-         <action key="" description="Overwrite" name="scinotes-overwrite"/>
-         <action key="" description="Page setup" name="scinotes-page-setup"/>
-         <action key="" description="Close all" name="scinotes-close-all"/>
-         <action key="" description="Close all but" name="scinotes-close-all-but"/>
-         <action key="" description="Convert quote to double quote" name="scinotes-double-quote"/>
-         <action key="" description="Line numbering" name="scinotes-line-numbering"/>
-         <action key="" description="Split view" name="scinotes-split-view"/>
+          <action key="OSSCKEY H" description="Auto complete (, [,..." name="scinotes-autocomplete-openers"/>
+          <action key="OSSCKEY Shift H" description="Auto complete keyword" name="scinotes-autocomplete-keyword"/>
+          <action key="OSSCKEY Shift G" description="Generate Help prototype" name="scinotes-help-prototype"/>
+          <action key="TAB" description="Tabify" name="scinotes-tabify"/>
+          <action key="Shift TAB" description="Untabify" name="scinotes-untabify"/>
+          <action key="OSSCKEY I" description="Indent" name="scinotes-indent"/>
+          <action key="OSSCKEY D" description="Comment" name="scinotes-comment"/>
+          <action key="OSSCKEY Shift D" description="Uncomment" name="scinotes-uncomment"/>
+          <action key="OSSCKEY Shift W" description="Remove trailing whites" name="scinotes-remove-whites"/>
+          <action key="OSSCKEY A" description="Select all" name="scinotes-select-all"/>
+          <action key="OSSCKEY B" description="Select block" name="scinotes-select-block"/>
+          <action key="OSSCKEY Shift T" description="Open current tab in a new window" name="scinotes-clone-current"/>
+          <action key="OSSCKEY Shift X" description="Export current tab in a new window" name="scinotes-export-current"/>
+          <action key="OSSCKEY C" description="Copy" name="scinotes-copy"/>
+          <action key="OSSCKEY X" description="Cut" name="scinotes-cut"/>
+          <action key="OSSCKEY V" description="Paste" name="scinotes-paste"/>
+          <action key="OSSCKEY Shift V" description="Paste a column" name="scinotes-paste-column"/>
+          <action key="OSSCKEY Shift Z" description="Repeat selection on column" name="scinotes-repeat-column"/>
+          <action key="OSSCKEY Z" description="Undo" name="scinotes-undo"/>
+          <action key="OSSCKEY Y" description="Redo" name="scinotes-redo"/>
+          <action key="OSSCKEY Shift C" description="Copy as HTML with line number" name="scinotes-copy-with-lines"/>
+          <action key="OSSCKEY N" description="New" name="scinotes-new"/>
+          <action key="OSSCKEY O" description="Open" name="scinotes-open"/>
+          <action key="OSSCKEY U" description="Open URL" name="scinotes-open-url"/>
+          <action key="OSSCKEY Shift O" description="Open source" name="scinotes-open-source"/>
+          <action key="OSSCKEY S" description="Save" name="scinotes-save"/>
+          <action key="OSSCKEY Shift S" description="Save as" name="scinotes-save-as"/>
+          <action key="OSSCKEY Shift R" description="Reload" name="scinotes-reload"/>
+          <action key="OSSCKEY Shift P" description="Print preview" name="scinotes-print-preview"/>
+          <action key="OSSCKEY P" description="Print" name="scinotes-print"/>
+          <action key="OSSCKEY W" description="Close" name="scinotes-close"/>
+          <action key="OSSCKEY Q" description="Exit" name="scinotes-exit"/>
+          <action key="OSSCKEY J" description="To lower case" name="scinotes-tolowercase"/>
+          <action key="OSSCKEY Shift J" description="To upper case" name="scinotes-touppercase"/>
+          <action key="OSSCKEY Shift A" description="Capitalize" name="scinotes-capitalize"/>
+          <action key="OSSCKEY F1" description="Help on keyword" name="scinotes-help-keyword"/>
+          <action key="OSSCKEY L" description="Load in Scilab" name="scinotes-load-scilab"/>
+          <action key="OSSCKEY Shift E" description="Execute in Scilab" name="scinotes-execute-scilab"/>
+          <action key="OSSCKEY E" description="Evalute selection" name="scinotes-evaluate-selection"/>
+          <action key="F5" description="Save and execute" name="scinotes-save-execute"/>
+          <action key="OSSCKEY F5" description="Save and execute all" name="scinotes-save-execute-all"/>
+          <action key="OSSCKEY F" description="Find" name="scinotes-find"/>
+          <action key="OSSCKEY K" description="Find next" name="scinotes-find-next"/>
+          <action key="OSSCKEY Shift K" description="Find previous" name="scinotes-find-previous"/>
+          <action key="F3" description="Incremental search" name="scinotes-incremental-search"/>
+          <action key="OSSCKEY M" description="Set anchor" name="scinotes-set-anchor"/>
+          <action key="OSSCKEY Shift M" description="Remove anchor" name="scinotes-remove-anchor"/>
+          <action key="OSSCKEY Shift LESS" description="Go to next anchor" name="scinotes-next-anchor"/>
+          <action key="OSSCKEY LESS" description="Go to previous anchor" name="scinotes-previous-anchor"/>
+          <action key="OSSCKEY G" description="Start Code Navigator" name="scinotes-code-navigator"/>
+          <action key="OSSCKEY Shift F" description="Search word in file" name="scinotes-word-file"/>
+          <action key="OSSCKEY Shift B" description="Search files" name="scinotes-search-files"/>
+          <action key="OSSCKEY SPACE" description="Keyword cmppletion" name="scinotes-completion"/>
+          <action key="F1" description="Help" name="scinotes-help"/>
+          <action key="Shift F1" description="About" name="scinotes-about"/>
+          <action key="OSSCKEY PAGE_DOWN" description="Next tab" name="scinotes-next-tab"/>
+          <action key="OSSCKEY PAGE_UP" description="Previous tab" name="scinotes-previous-tab"/>
+          <action key="DELETE" description="Delete" name="scinotes-delete"/>
+          <action key="OSSCKEY DOWN" description="Next paragraph" name="scinotes-next-paragraph"/>
+          <action key="OSSCKEY UP" description="Previous paragraph" name="scinotes-previous-paragraph"/>
+          <action key="" description="Save all" name="scinotes-save-all"/>
+          <action key="" description="Overwrite" name="scinotes-overwrite"/>
+          <action key="" description="Page setup" name="scinotes-page-setup"/>
+          <action key="" description="Close all" name="scinotes-close-all"/>
+          <action key="" description="Close all but" name="scinotes-close-all-but"/>
+          <action key="" description="Convert quote to double quote" name="scinotes-double-quote"/>
+          <action key="" description="Line numbering" name="scinotes-line-numbering"/>
         </action-folder>
         <action-folder name="Xcos">
-         <action key="Ctrl+S" description="Save diagramm" name="xcos-save"/>
+          <action key="OSSCKEY S" description="Save diagramm" name="xcos-save"/>
         </action-folder>
         <action-folder name="Variable Browser">
-         <action key="Ctrl+S" description="Save" name="variablebrowser-save"/>
+          <action key="OSSCKEY S" description="Save" name="variablebrowser-save"/>
         </action-folder>
         <action-folder name="Variable Editor">
-         <action key="Ctrl+S" description="Save variable" name="editvar-save"/>
+          <action key="OSSCKEY S" description="Save variable" name="editvar-save"/>
         </action-folder>
         <action-folder name="History Browser">
-         <action key="Ctrl+S" description="Save history" name="historybrowser-save"/>
+          <action key="OSSCKEY S" description="Save history" name="historybrowser-save"/>
         </action-folder>
         <action-folder name="File Browser">
-         <action key="Ctrl+S" description="Save file" name="filebrowser-save"/>
+          <action key="OSSCKEY S" description="Save file" name="filebrowser-save"/>
         </action-folder>
       </actions>
     </body>
   </shortcuts>
-</general>
\ No newline at end of file
+</general>
index 8f97889..0dece9b 100644 (file)
@@ -38,117 +38,115 @@ import org.scilab.modules.gui.utils.ScilabSwingUtilities;
  */
 public class SwingScilabColorChooser extends JDialog implements SimpleColorChooser {
 
-        private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-        private static final int HGAP = 10;
-        private static final int VGAP = 2;
+    private static final int HGAP = 10;
+    private static final int VGAP = 2;
 
-        private int elementId;
+    private int elementId;
 
-        private Color selectedColor;
+    private Color selectedColor;
 
-        private final JColorChooser colorChooser;
+    private final JColorChooser colorChooser;
 
-        /**
-         * Default constructor
-         * @param color the default Color
-         */
-        public SwingScilabColorChooser(Color color) {
-                super(new JFrame(), "Color Chooser", true);
-        ((JFrame) getParent()).setIconImage(new ImageIcon(ScilabSwingUtilities.findIcon("scilab", "256x256")).getImage());
+    /**
+     * Default constructor
+     * @param color the default Color
+     */
+    public SwingScilabColorChooser(Color color) {
+        super(new JFrame(), "Color Chooser", true);
+        getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
 
-                getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
-
-                /* Color chooser panel */
-                JPanel chooserPanel = new JPanel(new BorderLayout());
-                chooserPanel.setBorder(new TitledBorder(new EtchedBorder(), "Color"));
-                colorChooser = new JColorChooser();
-                chooserPanel.add(colorChooser);
-                if (color != null) {
-                        colorChooser.setColor(color);
-                }
+        /* Color chooser panel */
+        JPanel chooserPanel = new JPanel(new BorderLayout());
+        chooserPanel.setBorder(new TitledBorder(new EtchedBorder(), "Color"));
+        colorChooser = new JColorChooser();
+        chooserPanel.add(colorChooser);
+        if (color != null) {
+            colorChooser.setColor(color);
+        }
 
-            getContentPane().add(chooserPanel);
+        getContentPane().add(chooserPanel);
 
-            ScilabSwingUtilities.closeOnEscape(this);
+        ScilabSwingUtilities.closeOnEscape(this);
 
-                /* Buttons panel */
-            JPanel buttonsContainer = new JPanel(new FlowLayout());
-            JPanel buttonsPanel = new JPanel(new GridLayout(1, 2, HGAP, VGAP));
+        /* Buttons panel */
+        JPanel buttonsContainer = new JPanel(new FlowLayout());
+        JPanel buttonsPanel = new JPanel(new GridLayout(1, 2, HGAP, VGAP));
 
-            JButton okButton = new JButton("Ok");
-            buttonsPanel.add(okButton);
-            getRootPane().setDefaultButton(okButton);
-            okButton.addActionListener(new ActionListener() {
-              @Override
+        JButton okButton = new JButton("Ok");
+        buttonsPanel.add(okButton);
+        getRootPane().setDefaultButton(okButton);
+        okButton.addActionListener(new ActionListener() {
+            @Override
             public void actionPerformed(ActionEvent e) {
                 selectedColor = colorChooser.getColor();
                 dispose();
                 setVisible(false);
-              }
-            });
+            }
+        });
 
-            JButton canButton = new JButton("Cancel");
-            buttonsPanel.add(canButton);
-            canButton.addActionListener(new ActionListener() {
-              @Override
+        JButton canButton = new JButton("Cancel");
+        buttonsPanel.add(canButton);
+        canButton.addActionListener(new ActionListener() {
+            @Override
             public void actionPerformed(ActionEvent e) {
                 selectedColor = null;
                 dispose();
                 setVisible(false);
-              }
-            });
-
-            buttonsContainer.add(buttonsPanel);
-            getContentPane().add(buttonsContainer);
-
-            pack();
-
-            setResizable(false);
-        }
-
-        /**
-         * Set the element id for this file chooser
-         * @param id the id of the corresponding color chooser object
-         */
-        @Override
-        public void setElementId(int id) {
-                this.elementId = id;
-        }
-
-        /**
-         * Get the element id for this chooser
-         * @return id the id of the corresponding chooser object
-         */
-        @Override
-        public int getElementId() {
-                return this.elementId;
-        }
-
-        /**
-         * Retrieve the selected color, or null
-         * @return the selected color
-         */
-        @Override
-        public Color getSelectedColor() {
-                return selectedColor;
-        }
-
-        /**
-         * Set the default color
-         * @param color the default color
-         */
-        @Override
-        public void setDefaultColor(Color color) {
-                colorChooser.setColor(color);
-        }
-
-        /**
-         * Display the font chooser and wait for a user input
-         */
-        @Override
-        public void displayAndWait() {
-                setVisible(true);
-        }
+            }
+        });
+
+        buttonsContainer.add(buttonsPanel);
+        getContentPane().add(buttonsContainer);
+
+        pack();
+
+        setResizable(false);
+    }
+
+    /**
+     * Set the element id for this file chooser
+     * @param id the id of the corresponding color chooser object
+     */
+    @Override
+    public void setElementId(int id) {
+        this.elementId = id;
+    }
+
+    /**
+     * Get the element id for this chooser
+     * @return id the id of the corresponding chooser object
+     */
+    @Override
+    public int getElementId() {
+        return this.elementId;
+    }
+
+    /**
+     * Retrieve the selected color, or null
+     * @return the selected color
+     */
+    @Override
+    public Color getSelectedColor() {
+        return selectedColor;
+    }
+
+    /**
+     * Set the default color
+     * @param color the default color
+     */
+    @Override
+    public void setDefaultColor(Color color) {
+        colorChooser.setColor(color);
+    }
+
+    /**
+     * Display the font chooser and wait for a user input
+     */
+    @Override
+    public void displayAndWait() {
+        setVisible(true);
+    }
 
 }
index 13acaee..38e5114 100644 (file)
@@ -35,284 +35,299 @@ import org.scilab.modules.localization.Messages;
  */
 public class SwingScilabFileChooser extends JFileChooser implements SimpleFileChooser {
 
-       private static final long serialVersionUID = 1L;
-
-       private String[] selection;     // Path + filenames
-       private String selectionPath; // Path
-       private String[] selectionFileNames; // Filenames
-       private int selectionSize;
-       private int filterIndex;
-       private int maskSize;
-       private int dialogType;
-
-       private String[] maskDescription;
-
-       /**
-        * Default constructor
-        */
-       public SwingScilabFileChooser() {
-               super();
-
-
-               //System.out.println("[Constructor] SwingScilabFileChooser");
-               /** Bug 3231 fixed: do not explore all zip files on desktop under Windows */
-               //putClientProperty("FileChooser.useShellFolder", Boolean.FALSE);
-               /**
-                * Bug 4187 fixed: uigetdir() opens on "Desktop" and not on "Computer" on windows
-                * No need to use 'putClientProperty' anymore (bug 3231)
-                */
-               /* Bug 5111 : The Current directory have to be set before */
-               super.setCurrentDirectory(new File(ConfigManager.getLastOpenedDirectory()));
-       }
-
-       /**
-        * Set the title of the file chooser
-        * @param title the title to set
-        */
-       @Override
+    private static final long serialVersionUID = 1L;
+
+    private String[] selection; // Path + filenames
+    private String selectionPath; // Path
+    private String[] selectionFileNames; // Filenames
+    private int selectionSize;
+    private int filterIndex;
+    private int maskSize;
+    private int dialogType;
+
+    private String[] maskDescription;
+    private JFrame parent;
+
+    /**
+     * Default constructor
+     */
+    public SwingScilabFileChooser() {
+        super();
+
+
+        //System.out.println("[Constructor] SwingScilabFileChooser");
+        /** Bug 3231 fixed: do not explore all zip files on desktop under Windows */
+        //putClientProperty("FileChooser.useShellFolder", Boolean.FALSE);
+        /**
+         * Bug 4187 fixed: uigetdir() opens on "Desktop" and not on "Computer" on windows
+         * No need to use 'putClientProperty' anymore (bug 3231)
+         */
+        /* Bug 5111 : The Current directory have to be set before */
+        super.setCurrentDirectory(new File(ConfigManager.getLastOpenedDirectory()));
+    }
+
+    /**
+     * Set the title of the file chooser
+     * @param title the title to set
+     */
+    @Override
     public void setTitle(String title) {
-               super.setDialogTitle(title);
-       }
-
-       /**
-        * Set the mask & the mask description for the filechooser
-        * @param mask the mask to set
-        * @param fileMaskDescription the maskDescription to set
-        */
-       public void addMask(String[] mask, String[] fileMaskDescription) {
-
-               //size of the mask list
-               maskSize = mask.length;
-
-               //If the mask description is empty we allocate description
-               //according to the extensions given
-               if (fileMaskDescription == null || fileMaskDescription.length == 0) {
-                       for (int i = 0; i < mask.length; i++) {
-                               super.addChoosableFileFilter(new SciFileFilter(mask[i], null, i/*, maskSize*/));
-                       }
-               } else {
-                       //If the mask description is filled
-                       //we use those descriptions given by the user
-                       this.maskDescription = fileMaskDescription;
-                       for (int i = 0; i < mask.length; i++) {
-                               super.addChoosableFileFilter(new SciFileFilter(mask[i], maskDescription[i], i/*, maskSize*/));
-                       }
-               }
-       }
-
-       /**
-        * Set the initial directory used for file search
-        * @param path the default path
-        */
-       @Override
+        super.setDialogTitle(title);
+    }
+
+    /**
+     * Set the mask & the mask description for the filechooser
+     * @param mask the mask to set
+     * @param fileMaskDescription the maskDescription to set
+     */
+    public void addMask(String[] mask, String[] fileMaskDescription) {
+
+        //size of the mask list
+        maskSize = mask.length;
+
+        //If the mask description is empty we allocate description
+        //according to the extensions given
+        if (fileMaskDescription == null || fileMaskDescription.length == 0) {
+            for (int i = 0; i < mask.length; i++) {
+                super.addChoosableFileFilter(new SciFileFilter(mask[i], null, i/*, maskSize*/));
+            }
+        } else {
+            //If the mask description is filled
+            //we use those descriptions given by the user
+            this.maskDescription = fileMaskDescription;
+            for (int i = 0; i < mask.length; i++) {
+                super.addChoosableFileFilter(new SciFileFilter(mask[i], maskDescription[i], i/*, maskSize*/));
+            }
+        }
+    }
+
+    /**
+     * Set the initial directory used for file search
+     * @param path the default path
+     */
+    @Override
     public void setInitialDirectory(String path) {
-               // When empty string given
-               if (path.length() == 0) {
-                       return;
-               }
-               // Replace beginning of the path if is an environment variable
-               String newPath = path;
-               StringTokenizer tok = new StringTokenizer(path, File.separator);
-               if (tok.hasMoreTokens()) { /* It is possible that we don't have any more token here when
-                                             Scilab is started from / for example */
-                   String firstToken = tok.nextToken();
-                   if (firstToken != null && System.getenv(firstToken) != null)  {
-                       newPath = newPath.replaceFirst(firstToken, System.getenv(firstToken));
-                   }
-               }
-               super.setCurrentDirectory(new File(newPath));
-       }
-
-       /**
-        * Display this chooser and wait for user selection
-        */
-       @Override
+        // When empty string given
+        if (path.length() == 0) {
+            return;
+        }
+        // Replace beginning of the path if is an environment variable
+        String newPath = path;
+        StringTokenizer tok = new StringTokenizer(path, File.separator);
+        if (tok.hasMoreTokens()) {
+            /* It is possible that we don't have any more token here when
+                                          Scilab is started from / for example */
+            String firstToken = tok.nextToken();
+            if (firstToken != null && System.getenv(firstToken) != null)  {
+                newPath = newPath.replaceFirst(firstToken, System.getenv(firstToken));
+            }
+        }
+        super.setCurrentDirectory(new File(newPath));
+    }
+
+    /**
+     * Set the parent frame
+     * @param parent the parent frame
+     */
+    public void setParentFrame(JFrame parent) {
+        this.parent = parent;
+    }
+
+    /**
+     * Display this chooser and wait for user selection
+     */
+    @Override
     public void displayAndWait() {
-               JFrame parentFrame = new JFrame();
-        parentFrame.setIconImage(new ImageIcon(ScilabSwingUtilities.findIcon("scilab", "256x256")).getImage());
-               int returnValue = 0;
-               if (maskSize > 0) {
-                        setFileFilter(getChoosableFileFilters()[maskSize]);
-               }
-               if (this.dialogType == JFileChooser.SAVE_DIALOG) {
-                       returnValue = this.showSaveDialog(parentFrame);
-               } else {
-                       returnValue = this.showOpenDialog(parentFrame);
-               }
-
-               //User validate the uigetfile
-               if (returnValue == APPROVE_OPTION) {
-                       if (this.isMultiSelectionEnabled()) {
-                               File[] files = this.getSelectedFiles();
-                               selection = new String[files.length];
-                               selectionFileNames = new String[files.length];
-                               selectionSize = files.length;
-                               for (int i = 0; i < files.length; i++) {
-                                       selection[i] = files[i].getAbsolutePath();
-                                       selectionPath = files[i].getParentFile().getPath();
-                                       selectionFileNames[i] = files[i].getName();
-                               }
-                       } else {
-                               File file = this.getSelectedFile();
-
-                               if (this.dialogType == JFileChooser.SAVE_DIALOG) {
-                                       //Test if there is a file with the same name
-                                       if (file.exists()) {
-                                               int actionDialog = JOptionPane.showConfirmDialog(this,
-                                                               Messages.gettext("Replace existing file?"),
-                                                               Messages.gettext("File already exists"),
-                                                               JOptionPane.YES_NO_OPTION);
-
-                                               if (actionDialog != JOptionPane.YES_OPTION) {
-                                                       // Same as cancel case
-                                                       selection = new String[1];
-                                                       selection[0] = "";
-                                                       selectionSize = 0;
-                                                       selectionPath = "";
-                                                       selectionFileNames = new String[1];
-                                                       selectionFileNames[0] = "";
-                                                       //set the filter index of the JFileChooser at 0 if "cancel" button was selected
-                                                       filterIndex = 0;
-
-                                                       //return the filechooser's informations
-                                                       //they are stocked into FileChooserInfos
-                                                       FileChooserInfos.getInstance().setSelection(selection);
-                                                       FileChooserInfos.getInstance().setSelectionPathName(selectionPath);
-                                                       FileChooserInfos.getInstance().setSelectionFileNames(selectionFileNames);
-                                                       FileChooserInfos.getInstance().setSelectionSize(selectionSize);
-                                                       FileChooserInfos.getInstance().setFilterIndex(filterIndex);
-                                                       return;
-                                               }
-                                       }
-                               }
-
-                               selection = new String[1];
-                               selection[0] = file.getAbsolutePath();
-                               if (getFileSelectionMode() == DIRECTORIES_ONLY) {
-                                       selectionPath = file.getPath();
-                               } else {
-                                       selectionPath = file.getParentFile().getPath();
-                               }
-                               selectionFileNames = new String[1];
-                               selectionFileNames[0] = file.getName();
-                               selectionSize = 1;
-                       }
-
-                       //return the filechooser's informations
-                       //they are stocked into FileChooserInfos
-                       FileChooserInfos.getInstance().setSelection(selection);
-                       FileChooserInfos.getInstance().setSelectionPathName(selectionPath);
-                       FileChooserInfos.getInstance().setSelectionFileNames(selectionFileNames);
-                       FileChooserInfos.getInstance().setSelectionSize(selectionSize);
-
-                       //set the filter index at the last index
-                       //of the list box if the mask "All files" is selected
-                       javax.swing.filechooser.FileFilter allFilesSelected = getFileFilter();
-                       if (allFilesSelected.getDescription().equals("All Files")) {
-                               FileChooserInfos.getInstance().setFilterIndex(maskSize + 1);
-                       }
-                       //TODO
-                       ConfigManager.saveLastOpenedDirectory(selectionPath);
-               //User cancel the uigetfile
-               } else {
-                       selection = new String[1];
-                       selection[0] = "";
-                       selectionSize = 0;
-                       selectionPath = "";
-                       selectionFileNames = new String[1];
-                       selectionFileNames[0] = "";
-                       //set the filter index of the JFileChooser at 0 if "cancel" button was selected
-                       filterIndex = 0;
-
-                       //return the filechooser's informations
-                       //they are stocked into FileChooserInfos
-                       FileChooserInfos.getInstance().setSelection(selection);
-                       FileChooserInfos.getInstance().setSelectionPathName(selectionPath);
-                       FileChooserInfos.getInstance().setSelectionFileNames(selectionFileNames);
-                       FileChooserInfos.getInstance().setSelectionSize(selectionSize);
-                       FileChooserInfos.getInstance().setFilterIndex(filterIndex);
-               }
-
-
-
-       }
-
-       /**
-        * Get the number of files selected
-        * @return the number of files selected
-        */
-       @Override
+        JFrame parentFrame;
+        if (parent == null) {
+            parentFrame = new JFrame();
+        } else {
+            parentFrame = parent;
+        }
+
+        int returnValue = 0;
+        if (maskSize > 0) {
+            setFileFilter(getChoosableFileFilters()[maskSize]);
+        }
+        if (this.dialogType == JFileChooser.SAVE_DIALOG) {
+            returnValue = this.showSaveDialog(parentFrame);
+        } else {
+            returnValue = this.showOpenDialog(parentFrame);
+        }
+
+        //User validate the uigetfile
+        if (returnValue == APPROVE_OPTION) {
+            if (this.isMultiSelectionEnabled()) {
+                File[] files = this.getSelectedFiles();
+                selection = new String[files.length];
+                selectionFileNames = new String[files.length];
+                selectionSize = files.length;
+                for (int i = 0; i < files.length; i++) {
+                    selection[i] = files[i].getAbsolutePath();
+                    selectionPath = files[i].getParentFile().getPath();
+                    selectionFileNames[i] = files[i].getName();
+                }
+            } else {
+                File file = this.getSelectedFile();
+
+                if (this.dialogType == JFileChooser.SAVE_DIALOG) {
+                    //Test if there is a file with the same name
+                    if (file.exists()) {
+                        int actionDialog = JOptionPane.showConfirmDialog(this,
+                                           Messages.gettext("Replace existing file?"),
+                                           Messages.gettext("File already exists"),
+                                           JOptionPane.YES_NO_OPTION);
+
+                        if (actionDialog != JOptionPane.YES_OPTION) {
+                            // Same as cancel case
+                            selection = new String[1];
+                            selection[0] = "";
+                            selectionSize = 0;
+                            selectionPath = "";
+                            selectionFileNames = new String[1];
+                            selectionFileNames[0] = "";
+                            //set the filter index of the JFileChooser at 0 if "cancel" button was selected
+                            filterIndex = 0;
+
+                            //return the filechooser's informations
+                            //they are stocked into FileChooserInfos
+                            FileChooserInfos.getInstance().setSelection(selection);
+                            FileChooserInfos.getInstance().setSelectionPathName(selectionPath);
+                            FileChooserInfos.getInstance().setSelectionFileNames(selectionFileNames);
+                            FileChooserInfos.getInstance().setSelectionSize(selectionSize);
+                            FileChooserInfos.getInstance().setFilterIndex(filterIndex);
+                            return;
+                        }
+                    }
+                }
+
+                selection = new String[1];
+                selection[0] = file.getAbsolutePath();
+                if (getFileSelectionMode() == DIRECTORIES_ONLY) {
+                    selectionPath = file.getPath();
+                } else {
+                    selectionPath = file.getParentFile().getPath();
+                }
+                selectionFileNames = new String[1];
+                selectionFileNames[0] = file.getName();
+                selectionSize = 1;
+            }
+
+            //return the filechooser's informations
+            //they are stocked into FileChooserInfos
+            FileChooserInfos.getInstance().setSelection(selection);
+            FileChooserInfos.getInstance().setSelectionPathName(selectionPath);
+            FileChooserInfos.getInstance().setSelectionFileNames(selectionFileNames);
+            FileChooserInfos.getInstance().setSelectionSize(selectionSize);
+
+            //set the filter index at the last index
+            //of the list box if the mask "All files" is selected
+            javax.swing.filechooser.FileFilter allFilesSelected = getFileFilter();
+            if (allFilesSelected.getDescription().equals("All Files")) {
+                FileChooserInfos.getInstance().setFilterIndex(maskSize + 1);
+            }
+            //TODO
+            ConfigManager.saveLastOpenedDirectory(selectionPath);
+            //User cancel the uigetfile
+        } else {
+            selection = new String[1];
+            selection[0] = "";
+            selectionSize = 0;
+            selectionPath = "";
+            selectionFileNames = new String[1];
+            selectionFileNames[0] = "";
+            //set the filter index of the JFileChooser at 0 if "cancel" button was selected
+            filterIndex = 0;
+
+            //return the filechooser's informations
+            //they are stocked into FileChooserInfos
+            FileChooserInfos.getInstance().setSelection(selection);
+            FileChooserInfos.getInstance().setSelectionPathName(selectionPath);
+            FileChooserInfos.getInstance().setSelectionFileNames(selectionFileNames);
+            FileChooserInfos.getInstance().setSelectionSize(selectionSize);
+            FileChooserInfos.getInstance().setFilterIndex(filterIndex);
+        }
+
+
+
+    }
+
+    /**
+     * Get the number of files selected
+     * @return the number of files selected
+     */
+    @Override
     public int getSelectionSize() {
-               return selectionSize;
-       }
-
-       /**
-        * Get the names of selected files
-        * @return the names of selected files
-        */
-       @Override
+        return selectionSize;
+    }
+
+    /**
+     * Get the names of selected files
+     * @return the names of selected files
+     */
+    @Override
     public String[] getSelection() {
-               return selection;
-       }
+        return selection;
+    }
 
-       /**
-        * Set the flag indicating that we want only select directories
-        */
-       @Override
+    /**
+     * Set the flag indicating that we want only select directories
+     */
+    @Override
     public void setDirectorySelectionOnly() {
-               setFileSelectionMode(DIRECTORIES_ONLY);
-       }
-
-       /**
-        * Set the flag indicating that we can select multiple files
-        * @param multipleSelection is enable or not
-        */
-       @Override
+        setFileSelectionMode(DIRECTORIES_ONLY);
+    }
+
+    /**
+     * Set the flag indicating that we can select multiple files
+     * @param multipleSelection is enable or not
+     */
+    @Override
     public void setMultipleSelection(boolean multipleSelection) {
-               setMultiSelectionEnabled(multipleSelection);
-       }
-
-       /**
-        * Get the path of selected files
-        * @return selectionPath selected file(s) path
-        */
-       @Override
+        setMultiSelectionEnabled(multipleSelection);
+    }
+
+    /**
+     * Get the path of selected files
+     * @return selectionPath selected file(s) path
+     */
+    @Override
     public String getSelectionPathName() {
-               return selectionPath;
-       }
-
-       /**
-        * Get the names of selected files
-        * @return selectionFileNnames selected file(s) path
-        */
-       @Override
+        return selectionPath;
+    }
+
+    /**
+     * Get the names of selected files
+     * @return selectionFileNnames selected file(s) path
+     */
+    @Override
     public String[] getSelectionFileNames() {
-               return selectionFileNames;
-       }
-
-       /**
-        * Get the filter index
-        * @return this.getFilterIndex() filter index
-        */
-       @Override
+        return selectionFileNames;
+    }
+
+    /**
+     * Get the filter index
+     * @return this.getFilterIndex() filter index
+     */
+    @Override
     public int getFilterIndex() {
-               return getFilterIndex();
-       }
-
-       /**
-        * Set the flag indicating the filter index
-        * @param filterIndex index of the filter
-        */
-       public void setFilterIndex(int filterIndex) {
-               setFilterIndex(filterIndex);
-       }
-
-       /**
-        * Set the dialog type (save or open a file ?)
-        * @param dialogType the dialog type
-        */
-       @Override
+        return getFilterIndex();
+    }
+
+    /**
+     * Set the flag indicating the filter index
+     * @param filterIndex index of the filter
+     */
+    public void setFilterIndex(int filterIndex) {
+        setFilterIndex(filterIndex);
+    }
+
+    /**
+     * Set the dialog type (save or open a file ?)
+     * @param dialogType the dialog type
+     */
+    @Override
     public void setUiDialogType(int dialogType) {
-               this.dialogType = dialogType;
-       }
+        this.dialogType = dialogType;
+    }
 }
index a422e77..8eaf8c4 100644 (file)
@@ -7,10 +7,7 @@
     <Title text="Saving">\r
       <VBox>\r
         <Grid>\r
-          <Radiobutton gridx="1" gridy="1" weightx="0" anchor="baseline" listener="ActionListener" text="Save after ">\r
-            <xsl:if test="@kind='save'">\r
-              <xsl:attribute name="checked">checked</xsl:attribute>\r
-            </xsl:if>\r
+          <Radiobutton value="{@kind}" expected-value="save" gridx="1" gridy="1" weightx="0" anchor="baseline" listener="ActionListener" text="Save after ">\r
             <actionPerformed set="kind" value="save">\r
               <xsl:call-template name="context"/>\r
             </actionPerformed>\r
          <Label gridx="3" gridy="1" weightx="0" anchor="baseline" text=" command(s)" enable="{$enable}"/>\r
          <Panel gridx="4" gridy="1"/>\r
         </Grid>\r
+\r
         <HBox>\r
-          <Radiobutton listener="ActionListener" text="Save history file on quit">\r
-            <xsl:if test="@kind='quit'">\r
-              <xsl:attribute name="checked">checked</xsl:attribute>\r
-            </xsl:if>\r
+          <Radiobutton value="{@kind}" expected-value="quit" listener="ActionListener" text="Save history file on quit">\r
             <actionPerformed set="kind" value="quit">\r
               <xsl:call-template name="context"/>\r
             </actionPerformed>\r
           <Glue/>\r
         </HBox>\r
         <HBox>\r
-          <Radiobutton listener="ActionListener" text="Disable history management">\r
-            <xsl:if test="@kind='disable'">\r
-              <xsl:attribute name="checked">checked</xsl:attribute>\r
-            </xsl:if>\r
+          <Radiobutton value="{@kind}" expected-value="disable" listener="ActionListener" text="Disable history management">\r
             <actionPerformed set="kind" value="disable">\r
               <xsl:call-template name="context"/>\r
             </actionPerformed>\r
     <Title text="Settings">\r
       <Grid>\r
         <Label gridx="1" gridy="1" text="History file:"/>\r
-        <File gridx="2" gridy="1" href="{@history-file}" mask="*.scilab" desc="Choose a history file" listener="ActionListener">\r
-          <actionPerformed choose="history-file">\r
-            <xsl:call-template name="context"/>\r
-          </actionPerformed>\r
-        </File>\r
+          <FileSelector gridx="2" gridy="1" weightx="1" anchor="above_baseline"\r
+                        listener="EntryListener"\r
+                        href="{@history-file}"\r
+                       mask="*.txt"\r
+                       desc="Text files"\r
+                        dir-selection="false" >\r
+           <entryChanged choose="history-file">\r
+              <xsl:call-template name="context"/>\r
+            </entryChanged>\r
+          </FileSelector>\r
         <Label gridx="1" gridy="2" text="History lines:"/>\r
         <Panel gridx="2" gridy="2" >\r
           <xsl:call-template name="Select">\r
index 33f0921..6db7a94 100644 (file)
@@ -20,10 +20,10 @@ import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox;
 import org.w3c.dom.Node;
 
 /** Implementation of Checkbox compliant with extended management.
-*
-* @author Pierre GRADIT
-*
-*/
+ *
+ * @author Pierre GRADIT
+ *
+ */
 public class Checkbox extends SwingScilabCheckBox implements XComponent, XChooser {
 
     /** Universal identifier for serialization.
@@ -31,48 +31,64 @@ public class Checkbox extends SwingScilabCheckBox implements XComponent, XChoose
      */
     private static final long serialVersionUID = -7007541669965737408L;
 
+    private String selectedValue;
+    private String unselectedValue;
+
     /** Define the set of actuators.
-    *
-    * @return array of actuator names.
-    */
-    public final String [] actuators() {
-        String [] actuators = {"text", "checked"};
+     *
+     * @return array of actuator names.
+     */
+    public final String[] actuators() {
+        String[] actuators = {"enable", "text", "checked", "selected-value", "unselected-value"};
         return actuators;
     }
 
     /** Constructor.
-    *
-    * @param peer : associated view DOM node.
-    */
+     *
+     * @param peer : associated view DOM node.
+     */
     public Checkbox(final Node peer) {
         super();
         setOpaque(false);
-       setRequestFocusEnabled(true);
-       setFocusable(true);
-       
+        setRequestFocusEnabled(true);
+        setFocusable(true);
+
         refresh(peer);
     }
 
     /** Refresh the component by the use of actuators.
-    *
-    * @param peer the corresponding view DOM node
-    */
+     *
+     * @param peer the corresponding view DOM node
+     */
     public final void refresh(final Node peer) {
-        String text = XConfigManager.getAttribute(peer , "text");
+        String text = XConfigManager.getAttribute(peer, "text");
         if (!text.equals(text())) {
             text(text);
         }
 
-        String checked = XConfigManager.getAttribute(peer , "checked");
+        String selectedValue = XConfigManager.getAttribute(peer, "selected-value");
+        if (!selectedValue.equals(selected())) {
+            selected(selectedValue);
+        }
+
+        String unselectedValue = XConfigManager.getAttribute(peer, "unselected-value");
+        if (!unselectedValue.equals(unselected())) {
+            unselected(unselectedValue);
+        }
+
+        String checked = XConfigManager.getAttribute(peer, "checked");
         if (!checked.equals(checked())) {
             checked(checked);
         }
+
+        String enable = XConfigManager.getAttribute(peer, "enable", "true");
+        setEnabled(enable.equals("true"));
     }
 
     /** Sensor for 'text' attribute.
-    *
-    * @return the attribute value.
-    */
+     *
+     * @return the attribute value.
+     */
     public final String text() {
         String text = getText();
         if (text != null) {
@@ -83,11 +99,11 @@ public class Checkbox extends SwingScilabCheckBox implements XComponent, XChoose
     }
 
     /** Actuator for 'text' attribute.
-    *
-    * @param text : the attribute value.
-    */
+     *
+     * @param text : the attribute value.
+     */
     public final void text(final String text) {
-       if (text!=XConfigManager.NAV) {
+        if (text != XConfigManager.NAV) {
             setText(text);
         } else {
             setText(null);
@@ -95,9 +111,9 @@ public class Checkbox extends SwingScilabCheckBox implements XComponent, XChoose
     }
 
     /** Sensor for 'checked' attribute.
-    *
-    * @return the attribute value.
-    */
+     *
+     * @return the attribute value.
+     */
     public final String checked() {
         boolean state = isSelected();
         if (state) {
@@ -108,29 +124,76 @@ public class Checkbox extends SwingScilabCheckBox implements XComponent, XChoose
     }
 
     /** Actuator for 'checked' attribute.
-    *
-    * @param text : the attribute value.
-    */
+     *
+     * @param text : the attribute value.
+     */
     public final void checked(final String checked) {
-        boolean state =  checked.equals("checked");
+        boolean state = checked.equals("checked") || checked.equals("true");
         setSelected(state);
     }
 
+    /** Sensor for 'checked' attribute.
+     *
+     * @return the attribute value.
+     */
+    public final String selected() {
+        return selectedValue;
+    }
+
+    /** Actuator for 'checked' attribute.
+     *
+     * @param text : the attribute value.
+     */
+    public final void selected(final String selected) {
+        if (!selected.equals(XConfigManager.NAV)) {
+            selectedValue = selected;
+        } else {
+            selectedValue = null;
+        }
+    }
+
+    /** Sensor for 'checked' attribute.
+     *
+     * @return the attribute value.
+     */
+    public final String unselected() {
+        return unselectedValue;
+    }
+
+    /** Actuator for 'checked' attribute.
+     *
+     * @param text : the attribute value.
+     */
+    public final void unselected(final String unselected) {
+        if (!unselected.equals(XConfigManager.NAV)) {
+            unselectedValue = unselected;
+        } else {
+            unselectedValue = null;
+        }
+    }
+
     /** Actual response read by the listener.
-    *
-    * @return response read by the listener.
-    */
+     *
+     * @return response read by the listener.
+     */
     public final Object choose() {
         if (isSelected()) {
+            if (selectedValue != null) {
+                return selectedValue;
+            }
             return "checked";
         }
+
+        if (unselectedValue != null) {
+            return unselectedValue;
+        }
         return "unchecked";
     }
 
     /** Developer serialization method.
-    *
-    * @return equivalent signature.
-    */
+     *
+     * @return equivalent signature.
+     */
     public final String toString() {
         String signature = "CHECKBOX";
         if (!text().equals(XConfigManager.NAV)) {
index 617dd2a..917aafd 100644 (file)
 package org.scilab.modules.preferences.Component;
 
 import java.awt.Component;
+import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
 import javax.swing.Icon;
 import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
 
 import org.w3c.dom.Node;
 
@@ -52,8 +55,8 @@ public class Color extends JButton implements XComponent, XChooser {
      * Define the set of actuators.
      * @return array of actuator names.
      */
-    public final String [] actuators() {
-        String [] actuators = {"enable", "color"};
+    public final String[] actuators() {
+        String[] actuators = {"enable", "color"};
         return actuators;
     }
 
@@ -63,44 +66,46 @@ public class Color extends JButton implements XComponent, XChooser {
      */
     public Color(final Node peer) {
         super(new Icon() {
-                public final int getIconHeight() {
-                    return ICONDIM;
+            public final int getIconHeight() {
+                return ICONDIM;
+            }
+
+            public final int getIconWidth() {
+                return ICONDIM * 2;
+            }
+
+            public void paintIcon(Component c, Graphics g, int x, int y) {
+                if (c.isEnabled()) {
+                    g.setColor(c.getForeground());
+                    g.fillRect(x, y, getIconWidth() - 1, getIconHeight() - 1);
+                    g.setColor(java.awt.Color.BLACK);
+                    g.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 1);
+                } else {
+                    java.awt.Color color = c.getForeground();
+                    float hsb[] = new float[3];
+                    java.awt.Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);
+                    g.setColor(java.awt.Color.getHSBColor(hsb[0], hsb[1] * 0.2f, hsb[2] * 0.95f));
+                    g.fillRect(x, y, getIconWidth(), getIconHeight());
                 }
-
-                public final int getIconWidth() {
-                    return ICONDIM * 2;
-                }
-
-                public void paintIcon(Component c, Graphics g, int x, int y) {
-                    if (c.isEnabled()) {
-                        g.setColor(c.getForeground());
-                        g.fillRect(x, y, getIconWidth() - 1, getIconHeight() - 1);
-                        g.setColor(java.awt.Color.BLACK);
-                        g.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 1);
-                    } else {
-                        java.awt.Color color = c.getForeground();
-                        float hsb[] = new float[3];
-                        java.awt.Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);
-                        g.setColor(java.awt.Color.getHSBColor(hsb[0], hsb[1] * 0.2f, hsb[2] * 0.95f));
-                        g.fillRect(x, y, getIconWidth(), getIconHeight());
-                    }
-                }
-            });
+            }
+        });
 
         String color = XCommonManager.getAttribute(peer , "color", "000000");
         color(color);
         setOpaque(true);
         addActionListener(new ActionListener() {
-                public void actionPerformed(ActionEvent e) {
-                    java.awt.Color jColor = XCommonManager.getColor(color());
-                    ActionEvent transmit  = new ActionEvent(Color.this, e.getID(), "Color change", e.getWhen() + 1, e.getModifiers());
-                    colorChooser = new SwingScilabColorChooser(jColor);
-                    colorChooser.displayAndWait();
-                    if (actionListener != null) {
-                        actionListener.actionPerformed(transmit);
-                    }
+            public void actionPerformed(ActionEvent e) {
+                java.awt.Color jColor = XCommonManager.getColor(color());
+                ActionEvent transmit  = new ActionEvent(Color.this, e.getID(), "Color change", e.getWhen() + 1, e.getModifiers());
+                colorChooser = new SwingScilabColorChooser(jColor);
+                JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, Color.this);
+                colorChooser.setLocationRelativeTo(frame);
+                colorChooser.displayAndWait();
+                if (actionListener != null) {
+                    actionListener.actionPerformed(transmit);
                 }
-            });
+            }
+        });
 
         setRequestFocusEnabled(true);
         setFocusable(true);
@@ -137,7 +142,7 @@ public class Color extends JButton implements XComponent, XChooser {
      * @param text : the attribute value.
      */
     public final void color(final String color) {
-        java.awt.Color jColor= XCommonManager.getColor(color);
+        java.awt.Color jColor = XCommonManager.getColor(color);
         setForeground(jColor);
     }
 
diff --git a/scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/FileSelector.java b/scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/FileSelector.java
new file mode 100644 (file)
index 0000000..d5e3bc6
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - Pierre GRADIT
+ * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.preferences.Component;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+
+import javax.swing.GroupLayout;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+import org.scilab.modules.preferences.XCommonManager;
+import org.scilab.modules.preferences.XComponent;
+import org.scilab.modules.preferences.XChooser;
+import org.scilab.modules.preferences.XConfigManager;
+import org.scilab.modules.gui.bridge.filechooser.SwingScilabFileChooser;
+
+import org.w3c.dom.Node;
+
+/** Implementation of Entry compliant with extended management.
+ *
+ * @author Calixte DENIZET
+ *
+ */
+public class FileSelector extends Panel implements XComponent, XChooser, DocumentListener {
+
+    /** Universal identifier for serialization.
+     *
+     */
+    private static final long serialVersionUID = -7007541669965737408L;
+
+    private static final Color NORMALCOLOR = Color.BLACK;
+    private static final Color ERRORCOLOR = Color.RED;
+
+    private ActionListener actionListener;
+    private JTextField textField;
+    private JButton button;
+    private String currentDir = System.getProperty("user.home");
+    private boolean dirSelection;
+    private String previousPath;
+
+    /** Constructor.
+     *
+     * @param peer : associated view DOM node.
+     */
+    public FileSelector(final Node peer) {
+        super(peer);
+        setLayout(new GridBagLayout());
+
+        textField = new JTextField();
+        textField.setEditable(true);
+        textField.getDocument().addDocumentListener(this);
+
+        button = new JButton("...");
+        button.setPreferredSize(new Dimension(button.getPreferredSize().width, textField.getPreferredSize().height));
+        button.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, FileSelector.this);
+                SwingScilabFileChooser fileChooser = new SwingScilabFileChooser();
+                fileChooser.setInitialDirectory(currentDir);
+                fileChooser.setParentFrame(frame);
+                fileChooser.setMultipleSelection(false);
+                fileChooser.setFileSelectionMode(dirSelection ? SwingScilabFileChooser.DIRECTORIES_ONLY : SwingScilabFileChooser.FILES_ONLY);
+                String mask = XCommonManager.getAttribute(peer, "mask");
+                String desc = XCommonManager.getAttribute(peer, "desc");
+                if (!mask.equals(XCommonManager.NAV) && !desc.equals(XCommonManager.NAV)) {
+                    fileChooser.addMask(new String[] {mask}, new String[] {desc});
+                }
+                fileChooser.displayAndWait();
+
+                String[] paths = fileChooser.getSelection();
+                if (paths != null && paths.length != 0 && !paths[0].isEmpty()) {
+                    File file = new File(paths[0]);
+                    if (file.exists()) {
+                        if (dirSelection) {
+                            currentDir = file.getAbsolutePath();
+                        } else {
+                            currentDir = file.getParentFile().getAbsolutePath();
+                        }
+
+                        textField.setText(file.getAbsolutePath());
+                    }
+                }
+            }
+        });
+
+        GridBagConstraints gbc = new GridBagConstraints();
+        gbc.gridx = 0;
+        gbc.gridy = 0;
+        gbc.weightx = 1;
+        gbc.fill = GridBagConstraints.HORIZONTAL;
+        add(textField, gbc);
+        gbc.gridx = 1;
+        gbc.weightx = 0;
+        add(button, gbc);
+
+        textField.setRequestFocusEnabled(true);
+        textField.setFocusable(true);
+        button.setRequestFocusEnabled(true);
+        button.setFocusable(true);
+
+        String href = XConfigManager.getAttribute(peer, "href");
+        href(href);
+
+        String dirsel = XCommonManager.getAttribute(peer, "dir-selection", "false");
+        dirSelection = dirsel.equals("true");
+    }
+
+    public void addDocumentListener(DocumentListener listener) {
+        textField.getDocument().addDocumentListener(listener);
+    }
+
+    /** Define the set of actuators.
+     *
+     * @return array of actuator names.
+     */
+    public final String[] actuators() {
+        String[] actuators = {"enable", "href", "desc", "mask", "dir-selection"};
+        return actuators;
+    }
+
+    /** Refresh the component by the use of actuators.
+     *
+     * @param peer the corresponding view DOM node
+     */
+    public final void refresh(final Node peer) {
+        String href = XCommonManager.getAttribute(peer , "href");
+        if (!href.equals(href())) {
+            href(href);
+        }
+
+        String dirsel = XCommonManager.getAttribute(peer , "dir-selection", "false");
+        dirSelection = dirsel.equals("true");
+
+        String enable = XConfigManager.getAttribute(peer , "enable", "true");
+        textField.setEnabled(enable.equals("true"));
+        button.setEnabled(enable.equals("true"));
+    }
+
+    /** Sensor for 'href' attribute.
+     *
+     * @return the attribute value.
+     */
+    public final String href() {
+        if (checkPath()) {
+            return textField.getText();
+        }
+
+        return null;
+    }
+
+    /** Actuator for 'href' attribute.
+     *
+     * @param text : the attribute value.
+     */
+    public final void href(final String href) {
+        if (!href.equals(XCommonManager.NAV)) {
+            textField.setText(href);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void changedUpdate(DocumentEvent e) { }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void insertUpdate(DocumentEvent e) {
+        update();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void removeUpdate(DocumentEvent e) {
+        update();
+    }
+
+    private void update() {
+        if (checkPath() && actionListener != null) {
+            ActionEvent transmit = new ActionEvent(this, 0, "File change", System.currentTimeMillis(), 0);
+            actionListener.actionPerformed(transmit);
+        }
+    }
+
+    private boolean checkPath() {
+        String path = textField.getText();
+        if (path.isEmpty()) {
+            return false;
+        }
+
+        File file = new File(path);
+        boolean ok = false;
+        if (file.exists()) {
+            if (dirSelection) {
+                ok = file.isDirectory();
+            } else {
+                ok = file.isFile();
+            }
+        }
+
+        if (ok) {
+            textField.setForeground(NORMALCOLOR);
+        } else {
+            textField.setForeground(ERRORCOLOR);
+        }
+
+        return ok;
+    }
+
+    /** Actual response read by the listener.
+     *
+     * @return response read by the listener.
+     */
+    public final Object choose() {
+        return href();
+    }
+
+    /** Developer serialization method.
+     *
+     * @return equivalent signature.
+     */
+    public final String toString() {
+        String signature = "FileSelector";
+        String href = href();
+        if (href != null && !href.equals(XCommonManager.NAV)) {
+            signature += " href='" + href + "'";
+        }
+
+        return signature;
+    }
+
+    /** Registration of a single listener.
+     * @param listener for the unique actionListener.
+     */
+    public final void addActionListener(final ActionListener listener) {
+        actionListener = listener;
+    }
+
+}
+
index ed0c6fd..ca55a75 100644 (file)
@@ -56,7 +56,7 @@ public class FontSelector extends Panel implements XComponent, XChooser {
      * @return array of actuator names.
      */
     public final String [] actuators() {
-        return new String[]{"font-name", "font-face", "font-size", "enable"};
+        return new String[] {"font-name", "font-face", "font-size", "enable"};
     }
 
     /** Constructor.
@@ -74,27 +74,27 @@ public class FontSelector extends Panel implements XComponent, XChooser {
 
         button = new JButton("...");
         button.addActionListener(new ActionListener() {
-                public void actionPerformed(ActionEvent e) {
-                    JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, FontSelector.this);
-                    SwingScilabFontChooser fontChooser = new SwingScilabFontChooser(frame, font, false);
-                    fontChooser.setLocationRelativeTo(frame);
-                    fontChooser.displayAndWait();
-
-                    Font newFont = fontChooser.getSelectedFont();
-                    if (newFont != null && !newFont.equals(font)) {
-                        font = newFont;
-                        setTextField();
-                        if (actionListener != null) {
-                            actionListener.actionPerformed(new ActionEvent(FontSelector.this, 0, "Font Selector Value changed", System.currentTimeMillis(), 0));
-                        }
+            public void actionPerformed(ActionEvent e) {
+                JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, FontSelector.this);
+                SwingScilabFontChooser fontChooser = new SwingScilabFontChooser(frame, font, false);
+                fontChooser.setLocationRelativeTo(frame);
+                fontChooser.displayAndWait();
+
+                Font newFont = fontChooser.getSelectedFont();
+                if (newFont != null && !newFont.equals(font)) {
+                    font = newFont;
+                    setTextField();
+                    if (actionListener != null) {
+                        actionListener.actionPerformed(new ActionEvent(FontSelector.this, 0, "Font Selector Value changed", System.currentTimeMillis(), 0));
                     }
                 }
-            });
+            }
+        });
 
         layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(textField).addComponent(button));
         layout.setVerticalGroup(layout.createParallelGroup().addComponent(textField).addComponent(button));
 
-       setRequestFocusEnabled(true);
+        setRequestFocusEnabled(true);
         setFocusable(true);
 
         String fontname = XConfigManager.getAttribute(peer , "font-name");
@@ -155,16 +155,16 @@ public class FontSelector extends Panel implements XComponent, XChooser {
      */
     public final String fontface() {
         switch (font.getStyle()) {
-        case Font.PLAIN :
-            return "plain";
-        case Font.BOLD :
-            return "bold";
-        case Font.ITALIC :
-            return "italic";
-        case Font.BOLD | Font.ITALIC :
-            return "bold italic";
-        default :
-            return "plain";
+            case Font.PLAIN :
+                return "plain";
+            case Font.BOLD :
+                return "bold";
+            case Font.ITALIC :
+                return "italic";
+            case Font.BOLD | Font.ITALIC :
+                return "bold italic";
+            default :
+                return "plain";
         }
     }
 
@@ -225,7 +225,7 @@ public class FontSelector extends Panel implements XComponent, XChooser {
      * @return response read by the listener.
      */
     public final Object choose() {
-        return new String[]{fontname(), fontface(), fontsize()};
+        return new String[] {fontname(), fontface(), fontsize()};
     }
 
 
@@ -261,4 +261,3 @@ public class FontSelector extends Panel implements XComponent, XChooser {
         return signature.toString();
     }
 }
-
index 0ee9997..fbb8a89 100644 (file)
 
 package org.scilab.modules.preferences.Component;
 
+import java.awt.Color;
 import java.awt.Cursor;
 
 import org.scilab.modules.preferences.XConfigManager;
 
 import org.w3c.dom.Node;
 
-/** 
+/**
  * Implementation of Link compliant with extended management.
  * @author Vincent COUVERT
  */
 public class Link extends Label {
 
-       private static final long serialVersionUID = -8915028261763299611L;
-
-       /** 
-        * Constructor.
-        * @param peer : associated view DOM node.
-        */
-       public Link(final Node peer) {
-               super(peer);
-               setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
-       }
-
-       /**
-        * Refresh the component by the use of actuators.
-        * @param peer the corresponding view DOM node
-        */
-       public void refresh(final Node peer) {
-               super.refresh(peer);
-               /* Force text to be underlined */
-               String text = "<HTML><U>" + XConfigManager.getAttribute(peer , "text") + "</U></HTML>";
-               if (!text.equals(text())) {
-                       text(text);
-               }
-               /* Force text to be blue */
-               foreground("#0000FF");
-       }
+    private static final long serialVersionUID = -8915028261763299611L;
+
+    /**
+     * Constructor.
+     * @param peer : associated view DOM node.
+     */
+    public Link(final Node peer) {
+        super(peer);
+        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+        refresh(peer);
+    }
+
+    /**
+     * Refresh the component by the use of actuators.
+     * @param peer the corresponding view DOM node
+     */
+    public void refresh(final Node peer) {
+        super.refresh(peer);
+        /* Force text to be underlined */
+        String text = "<HTML><U>" + XConfigManager.getAttribute(peer , "text") + "</U></HTML>";
+        if (!text.equals(text())) {
+            text(text);
+        }
+
+        String enable = XConfigManager.getAttribute(peer , "enable", "true");
+        if (enable.equals("true")) {
+            setForeground(Color.BLUE);
+        } else {
+            if (getParent() != null) {
+                setForeground(getParent().getBackground().darker());
+            }
+        }
+    }
 }
 
index e220b85..ccaec10 100644 (file)
@@ -20,10 +20,10 @@ import org.scilab.modules.gui.bridge.radiobutton.SwingScilabRadioButton;
 import org.w3c.dom.Node;
 
 /** Implementation of Radiobutton compliant with extended management.
-*
-* @author Pierre GRADIT
-*
-*/
+ *
+ * @author Pierre GRADIT
+ *
+ */
 public class Radiobutton extends SwingScilabRadioButton implements XComponent, XChooser {
 
     /** Universal identifier for serialization.
@@ -31,19 +31,21 @@ public class Radiobutton extends SwingScilabRadioButton implements XComponent, X
      */
     private static final long serialVersionUID = -7007541669965737408L;
 
+    private String expectedValue;
+
     /** Define the set of actuators.
-    *
-    * @return array of actuator names.
-    */
+     *
+     * @return array of actuator names.
+     */
     public final String [] actuators() {
-        String [] actuators = {"enable", "text", "checked"};
+        String [] actuators = {"enable", "text", "checked", "value", "expected-value"};
         return actuators;
     }
 
     /** Constructor.
-    *
-    * @param peer : associated view DOM node.
-    */
+     *
+     * @param peer : associated view DOM node.
+     */
     public Radiobutton(final Node peer) {
         super();
         setOpaque(false);
@@ -51,28 +53,39 @@ public class Radiobutton extends SwingScilabRadioButton implements XComponent, X
     }
 
     /** Refresh the component by the use of actuators.
-    *
-    * @param peer the corresponding view DOM node
-    */
+     *
+     * @param peer the corresponding view DOM node
+     */
     public final void refresh(final Node peer) {
-        String text = XConfigManager.getAttribute(peer , "text");
+        String text = XConfigManager.getAttribute(peer, "text");
         if (!text.equals(text())) {
             text(text);
         }
 
-        String checked = XConfigManager.getAttribute(peer , "checked");
+        String checked = XConfigManager.getAttribute(peer, "checked");
+        if (checked.equals(XConfigManager.NAV)) {
+            expectedValue = XConfigManager.getAttribute(peer, "expected-value");
+            if (XConfigManager.getAttribute(peer, "value").equals(expectedValue)) {
+                checked = "checked";
+            } else {
+                checked = "unchecked";
+            }
+        } else {
+            expectedValue = null;
+        }
+
         if (!checked.equals(checked())) {
             checked(checked);
         }
-        String enable     = XConfigManager.getAttribute(peer , "enable", "true");
-        setEnabled(enable.equals("true"));
 
+        String enable = XConfigManager.getAttribute(peer, "enable", "true");
+        setEnabled(enable.equals("true"));
     }
 
     /** Sensor for 'text' attribute.
-    *
-    * @return the attribute value.
-    */
+     *
+     * @return the attribute value.
+     */
     public final String text() {
         String text = getText();
         if (text != null) {
@@ -83,11 +96,11 @@ public class Radiobutton extends SwingScilabRadioButton implements XComponent, X
     }
 
     /** Actuator for 'text' attribute.
-    *
-    * @param text : the attribute value.
-    */
+     *
+     * @param text : the attribute value.
+     */
     public final void text(final String text) {
-       if (text!=XConfigManager.NAV) {
+        if (text != XConfigManager.NAV) {
             setText(text);
         } else {
             setText(null);
@@ -95,9 +108,9 @@ public class Radiobutton extends SwingScilabRadioButton implements XComponent, X
     }
 
     /** Sensor for 'checked' attribute.
-    *
-    * @return the attribute value.
-    */
+     *
+     * @return the attribute value.
+     */
     public final String checked() {
         boolean state = isSelected();
         if (state) {
@@ -108,19 +121,23 @@ public class Radiobutton extends SwingScilabRadioButton implements XComponent, X
     }
 
     /** Actuator for 'checked' attribute.
-    *
-    * @param text : the attribute value.
-    */
+     *
+     * @param text : the attribute value.
+     */
     public final void checked(final String checked) {
-        boolean state =  checked.equals("checked");
+        boolean state = checked.equals("checked");
         setSelected(state);
     }
 
     /** Actual response read by the listener.
-    *
-    * @return response read by the listener.
-    */
+     *
+     * @return response read by the listener.
+     */
     public final Object choose() {
+        if (expectedValue != null) {
+            return expectedValue;
+        }
+
         if (isSelected()) {
             return "checked";
         }
@@ -128,9 +145,9 @@ public class Radiobutton extends SwingScilabRadioButton implements XComponent, X
     }
 
     /** Developer serialization method.
-    *
-    * @return equivalent signature.
-    */
+     *
+     * @return equivalent signature.
+     */
     public final String toString() {
         String signature = "RadioButton";
         if (!text().equals(XConfigManager.NAV)) {
@@ -142,4 +159,3 @@ public class Radiobutton extends SwingScilabRadioButton implements XComponent, X
         return signature;
     }
 }
-
index 7fe2c3d..e4dc051 100644 (file)
@@ -47,30 +47,30 @@ class ComponentFactory {
 
     static {
         actions.put("Scroll", new MyAction() {
-                public Component getComponent(final Node node) {
-                    return new Scroll(node, new JPanel());
-                }
-            });
+            public Component getComponent(final Node node) {
+                return new Scroll(node, new JPanel());
+            }
+        });
         actions.put("#text", new MyAction() {
-                public Component getComponent(final Node node) {
-                    return new JLabel(node.getNodeValue());
-                }
-            });
+            public Component getComponent(final Node node) {
+                return new JLabel(node.getNodeValue());
+            }
+        });
         actions.put("VSpace", new MyAction() {
-                public Component getComponent(final Node node) {
-                    return Box.createVerticalStrut(XConfigManager.getInt(node, "height", SPACE));
-                }
-            });
+            public Component getComponent(final Node node) {
+                return Box.createVerticalStrut(XConfigManager.getInt(node, "height", SPACE));
+            }
+        });
         actions.put("HSpace", new MyAction() {
-                public Component getComponent(final Node node) {
-                    return Box.createHorizontalStrut(XConfigManager.getInt(node, "height", SPACE));
-                }
-            });
+            public Component getComponent(final Node node) {
+                return Box.createHorizontalStrut(XConfigManager.getInt(node, "height", SPACE));
+            }
+        });
         actions.put("Glue", new MyAction() {
-                public Component getComponent(final Node node) {
-                    return Box.createGlue();
-                }
-            });
+            public Component getComponent(final Node node) {
+                return Box.createGlue();
+            }
+        });
     }
 
     public static final Component getComponent(final Node node) {
@@ -88,12 +88,13 @@ class ComponentFactory {
             try {
                 componentClass = (Class<Component>) Class.forName(X_PACKAGE + tag);
             } catch (ClassNotFoundException e) {
+                System.err.println(e);
                 return new XStub(node, "ClassNotFoundException");
             }
 
             try {
                 // First with a Node as argument
-                Class[] parameter = new Class[]{Node.class};
+                Class[] parameter = new Class[] {Node.class};
                 constructor = componentClass.getConstructor(parameter);
             } catch (NoSuchMethodException e) {
                 System.err.println("NoSuchMethodException:" + e);
@@ -108,7 +109,7 @@ class ComponentFactory {
         }
 
         try {
-            component = (Component) constructor.newInstance(new Object[]{node});
+            component = (Component) constructor.newInstance(new Object[] {node});
         } catch (InstantiationException e) {
             System.err.println("InstantiationException:" + e);
             return new XStub(node, "InstantiationException");
@@ -159,7 +160,7 @@ class ComponentFactory {
         public XStub(final Node node, final String cause) {
             super();
             Border red = BorderFactory.createLineBorder(Color.RED);
-            TitledBorder title = BorderFactory.createTitledBorder(red, node.getNodeName());
+            TitledBorder title = BorderFactory.createTitledBorder(red, node.getNodeName() + " " + cause);
             Dimension dimension = new Dimension(D_WIDTH, D_HEIGHT);
             setPreferredSize(dimension);
             setOpaque(false);
index 23f17fc..34e3124 100644 (file)
@@ -30,6 +30,7 @@ import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Stack;
 import java.util.StringTokenizer;
 
 import javax.swing.JDialog;
@@ -140,7 +141,7 @@ public abstract class XCommonManager {
         long nextTime  = System.currentTimeMillis();
         long deltaTime = nextTime - time;
         if (performances) {
-            System.out.println((msg.startsWith("*")?"":" |  ") + msg + " in " + deltaTime + " ms.");
+            System.out.println((msg.startsWith("*") ? "" : " |  ") + msg + " in " + deltaTime + " ms.");
         }
         time = nextTime;
     }
@@ -237,10 +238,10 @@ public abstract class XCommonManager {
         List<File> list = new ArrayList<File>();
         File modulesDir = new File(SCI + "/modules/");
         File[] modules = modulesDir.listFiles(new FileFilter() {
-                public boolean accept(File f) {
-                    return f.isDirectory();
-                }
-            });
+            public boolean accept(File f) {
+                return f.isDirectory();
+            }
+        });
 
         for (File module : modules) {
             File etc = new File(module, "/etc/");
@@ -266,10 +267,10 @@ public abstract class XCommonManager {
 
             for (File etc : etcs) {
                 File[] xsls = etc.listFiles(new FilenameFilter() {
-                        public boolean accept(File dir, String name) {
-                            return name.endsWith(".xsl") && name.startsWith("XConfiguration");
-                        }
-                    });
+                    public boolean accept(File dir, String name) {
+                        return name.endsWith(".xsl") && name.startsWith("XConfiguration");
+                    }
+                });
                 for (File xsl : xsls) {
                     try {
                         buffer.append("<xsl:import href=\"").append(xsl.getCanonicalPath()).append("\"/>\n");
@@ -324,7 +325,7 @@ public abstract class XCommonManager {
      */
     public static Element getElementByContext(final String context) {
         String[] ids = context.split("/");
-        Element element = (Element) document.getDocumentElement();
+        Element element = document.getDocumentElement();
         for (int i = 0; i < ids.length; i++) {
             int index = Integer.parseInt(ids[i]);
             // get the element with corresponding index (filter text nodes)
@@ -360,7 +361,9 @@ public abstract class XCommonManager {
         Node action = actions[0];
         // All actions must be of the same kind.
 
-        if (!getAttribute(action, "set").equals(NAV)) {
+        boolean enable = getAttribute(action, "enable").equals(NAV) || getAttribute(action, "enable").equals("true");
+
+        if (!getAttribute(action, "set").equals(NAV) && enable) {
             for (int i = 0; i < actions.length; i++) {
                 action = actions[i];
                 String context = getAttribute(action, "context");
@@ -369,6 +372,7 @@ public abstract class XCommonManager {
                 String attribute = getAttribute(action, "set");
                 if (element != null) {
                     element.setAttribute(attribute, value);
+                    XConfiguration.addModifiedPath(getNodePath(element));
                 }
             }
             refreshDisplay();
@@ -376,7 +380,7 @@ public abstract class XCommonManager {
             return true;
         }
 
-        if (!getAttribute(action, "insert").equals(NAV)) {
+        if (!getAttribute(action, "insert").equals(NAV) && enable) {
             for (int i = 0; i < actions.length; i++) {
                 action = actions[i];
                 String context = getAttribute(action, "context");
@@ -419,7 +423,7 @@ public abstract class XCommonManager {
             return true;
         }
 
-        if (!getAttribute(action, "delete").equals(NAV)) {
+        if (!getAttribute(action, "delete").equals(NAV) && enable) {
             for (int i = 0; i < actions.length; i++) {
                 action = actions[i];
                 String context = getAttribute(action, "context");
@@ -445,7 +449,7 @@ public abstract class XCommonManager {
                             deleted = node;
                             break;
                         }
-                        delete --;
+                        delete--;
                     }
                 }
                 if (element != null && deleted != null) {
@@ -458,9 +462,10 @@ public abstract class XCommonManager {
             return true;
         }
 
-        if (!getAttribute(action, "choose").equals(NAV)) {
+        if (!getAttribute(action, "choose").equals(NAV) && enable) {
             String context = getAttribute(action, "context");
             Element element = getElementByContext(context);
+
             if (source == null) {
                 return false;
             }
@@ -481,6 +486,7 @@ public abstract class XCommonManager {
                         } else {
                             element.setAttribute(attribute, value.toString());
                         }
+                        XConfiguration.addModifiedPath(getNodePath(element));
                     }
                     refreshDisplay();
                     updated = true;
@@ -493,6 +499,31 @@ public abstract class XCommonManager {
         return false;
     }
 
+    public static final String getNodePath(Node node) {
+        StringBuilder buffer = new StringBuilder("/");
+        Stack<String> stack = new Stack<String>();
+        Node n = node;
+
+        while (n != null) {
+            stack.push(n.getNodeName());
+            n = n.getParentNode();
+        }
+
+        if (stack.size() >= 3) {
+            stack.pop();
+            stack.pop();
+        } else {
+            return null;
+        }
+
+        while (!stack.empty()) {
+            buffer.append("/");
+            buffer.append(stack.pop());
+        }
+
+        return buffer.toString();
+    }
+
     /**
      * Sentinel string for attribute consulting.
      */
@@ -585,8 +616,8 @@ public abstract class XCommonManager {
         if (response.equals(NAV) || response.equals("")) {
             return value;
         }
-       
-       return response.equalsIgnoreCase("true");
+
+        return response.equalsIgnoreCase("true");
     }
 
     /**
index 6fd1a4d..a9ae1e7 100644 (file)
@@ -63,6 +63,7 @@ public final class XConfigManager extends XCommonManager {
     /** User configuration file.*/
     private static final String USER_CONFIG_FILE = ScilabCommons.getSCIHOME() + "/XConfiguration.xml";
 
+
     /**
      * Constructor blocked, singleton pattern.
      */
@@ -91,18 +92,18 @@ public final class XConfigManager extends XCommonManager {
 
         // Plug in resize
         //dialog.setResizable(false);
-        dialog.addComponentListener(new ComponentAdapter(){
-                public void componentResized(ComponentEvent e) {
-                    Element element = (Element) document.getDocumentElement();
-                    Dimension dimension = dialog.getSize();
-                    int height = XConfigManager.getInt(element, "height", 0);
-                    int width = XConfigManager.getInt(element, "width",  0);
-                    if (Math.abs(((double) height) - dimension.getHeight()) > 0.1 && Math.abs(((double) width) - dimension.getWidth()) > 0.1 ) {
-                        element.setAttribute("height", Integer.toString((int) dimension.getHeight()));
-                        element.setAttribute("width", Integer.toString((int) dimension.getWidth()));
-                    }
+        dialog.addComponentListener(new ComponentAdapter() {
+            public void componentResized(ComponentEvent e) {
+                Element element = (Element) document.getDocumentElement();
+                Dimension dimension = dialog.getSize();
+                int height = XConfigManager.getInt(element, "height", 0);
+                int width = XConfigManager.getInt(element, "width",  0);
+                if (Math.abs(((double) height) - dimension.getHeight()) > 0.1 && Math.abs(((double) width) - dimension.getWidth()) > 0.1 ) {
+                    element.setAttribute("height", Integer.toString((int) dimension.getHeight()));
+                    element.setAttribute("width", Integer.toString((int) dimension.getWidth()));
                 }
-            });
+            }
+        });
 
         // Set up correspondence
         correspondance = new HashMap<Component, XSentinel>();
@@ -143,7 +144,7 @@ public final class XConfigManager extends XCommonManager {
         Element toolbox = (Element) toolboxes.item(0);
         toolboxes = toolbox.getChildNodes();
 
-        if (toolboxes.getLength()>0) {
+        if (toolboxes.getLength() > 0) {
             System.err.println("Recover from inconsistent state...");
             while (toolbox.hasChildNodes()) {
                 toolbox.removeChild(toolbox.getFirstChild());
@@ -157,10 +158,10 @@ public final class XConfigManager extends XCommonManager {
         toolbox.appendChild(body);
 
         List<ToolboxInfos> infos = ScilabPreferences.getToolboxesInfos();
-        System.out.println(""+infos.size()+ " toolboxes loaded.");
-        for (int i = 0; i<infos.size(); i++) {
+        System.out.println("" + infos.size() + " toolboxes loaded.");
+        for (int i = 0; i < infos.size(); i++) {
             ToolboxInfos info = infos.get(i);
-            String UserToolboxToken = info.getName().replace(' ','_');
+            String UserToolboxToken = info.getName().replace(' ', '_');
             String UserToolboxFile = ScilabCommons.getSCIHOME() + "/" + UserToolboxToken + ".xml";
             createUserCopy(info.getPrefFile(), UserToolboxFile);
             // Building document fragment
@@ -186,24 +187,26 @@ public final class XConfigManager extends XCommonManager {
         // Toolboxes files
         NodeList toolboxes = document.getElementsByTagName("toolboxes");
         Element toolbox = (Element) toolboxes.item(0);
-        toolbox.removeChild(toolbox.getFirstChild()); // body
-        List<ToolboxInfos> infos = ScilabPreferences.getToolboxesInfos();
-        toolboxes = toolbox.getChildNodes();
-        if (infos.size() != toolboxes.getLength()) {
-            System.err.println("Can't hook toolboxes [3]");
-            return;
-        }
-        for (int i = 0; i<infos.size(); i++) {
-            Node ToolboxNode = toolboxes.item(i);
-            if (ToolboxNode != null) {
-                ToolboxInfos info = infos.get(i);
-                String UserToolboxFile = ScilabCommons.getSCIHOME() + "/" + info.getName().replace(' ','_') + ".xml";
-                writeDocument(UserToolboxFile, ToolboxNode.getFirstChild());
-                //toolbox.removeChild(ToolboxNode);
+        if (toolbox.getFirstChild() != null) {
+            toolbox.removeChild(toolbox.getFirstChild()); // body
+            List<ToolboxInfos> infos = ScilabPreferences.getToolboxesInfos();
+            toolboxes = toolbox.getChildNodes();
+            if (infos.size() != toolboxes.getLength()) {
+                System.err.println("Can't hook toolboxes [3]");
+                return;
+            }
+            for (int i = 0; i < infos.size(); i++) {
+                Node ToolboxNode = toolboxes.item(i);
+                if (ToolboxNode != null) {
+                    ToolboxInfos info = infos.get(i);
+                    String UserToolboxFile = ScilabCommons.getSCIHOME() + "/" + info.getName().replace(' ', '_') + ".xml";
+                    XConfiguration.writeDocument(UserToolboxFile, ToolboxNode.getFirstChild());
+                    //toolbox.removeChild(ToolboxNode);
+                }
             }
         }
         // Main file
-        writeDocument(USER_CONFIG_FILE, document);
+        XConfiguration.writeDocument(USER_CONFIG_FILE, document);
     }
 
     /** Interpret action.
@@ -237,21 +240,23 @@ public final class XConfigManager extends XCommonManager {
             WriteUserDocuments();
             dialog.dispose();
             updated = false;
+            XConfiguration.fireXConfigurationEvent();
             return true;
         }
         if (callback.equals("Apply")) {
             updated = false;
             WriteUserDocuments();
+            XConfiguration.fireXConfigurationEvent();
             return true;
         }
         if (callback.equals("Default")) {
             reloadTransformer(SCILAB_CONFIG_XSL);
-           document = XConfiguration.createDocument();
-           writeDocument(USER_CONFIG_FILE, document);
+            document = XConfiguration.createDocument();
+            writeDocument(USER_CONFIG_FILE, document);
             List<ToolboxInfos> infos = ScilabPreferences.getToolboxesInfos();
-            for (int i=0; i<infos.size(); i++) {
+            for (int i = 0; i < infos.size(); i++) {
                 ToolboxInfos info = infos.get(i);
-                String UserToolboxFile = ScilabCommons.getSCIHOME() + "/" + info.getName().replace(' ','_') + ".xml";
+                String UserToolboxFile = ScilabCommons.getSCIHOME() + "/" + info.getName().replace(' ', '_') + ".xml";
                 refreshUserCopy(info.getPrefFile(), UserToolboxFile);
             }
             readUserDocuments();
@@ -261,31 +266,12 @@ public final class XConfigManager extends XCommonManager {
             return true;
         }
         if (callback.equals("Cancel")) {
-            readUserDocuments();
-            /* TODO advertise it!
-               if (updated) {
-               <<some advertising statement>>
-               }
-            */
+            dialog.dispose();
+            XConfiguration.clearModifiedPath();
             updated = false;
             refreshDisplay();
             return true;
         }
         return false;
     }
-
-    /** TODO How to impact modification of preferences ?
-     *
-     */
-    public static void subscribeUpdate() {
-    }
-
-    /** TODO How to impact modification of preferences ?
-     *
-     */
-    public static void notifyUpdate() {
-    }
 }
-
-
-
index 1cf622f..cd8465f 100644 (file)
@@ -31,6 +31,7 @@ import javax.swing.border.Border;
 import javax.swing.border.TitledBorder;
 
 import org.scilab.modules.preferences.Component.Entry;
+import org.scilab.modules.preferences.Component.FileSelector;
 import org.scilab.modules.preferences.Component.Scroll;
 import org.scilab.modules.preferences.Component.Table;
 import org.scilab.modules.preferences.Component.Select;
@@ -189,6 +190,9 @@ public class XUpdateVisitor {
         if (node.getNodeName().equals("actionPerformed")) {
             return false;
         }
+        if (node.getNodeName().equals("entryChanged")) {
+            return false;
+        }
         // b. Text nodes with only invisible characters are invisible.
         if (node.getNodeName().equals("#text")) {
             if (node.getNodeValue().replaceAll("^[ \t\n]+$", "").equals("")) {
@@ -253,6 +257,11 @@ public class XUpdateVisitor {
                 ((Entry) component).getDocument().addDocumentListener(sentinel);
                 return;
             }
+
+            if (component instanceof FileSelector) {
+                ((FileSelector) component).addDocumentListener(sentinel);
+                return;
+            }
         }
 
         if (listener.equals("TableListener")) {
index c5ef980..7b104cf 100644 (file)
@@ -1,21 +1,16 @@
 <?xml version="1.0" encoding="utf-8"?>
 <scinotes>
   <body>
-    <scinotes-preferences restart-reopen="true" reload-unedited="true" add-line-termination="true" number-of-entries="5" encoding="utf-8" eol="Unix(LF)"/>
+    <scinotes-preferences restart-reopen="true" add-line-termination="true" number-of-recently-open="5" encoding="utf-8" eol="Unix(LF)" scinotes="true" cmd="" external-cmd="true"/>
   </body>
   <display>
     <body>
-      <scinotes-display highlight-current-line="true" current-line-color="#facade" show-line-numbers="true" wrap-lines="true"/>
+      <scinotes-display highlight-current-line="true" current-line-color="#FACADE" show-line-numbers="true" wrap-lines="true" keywords-colorization="true" highlight-brackets="true" brackets-color="#E40087" brackets-highlightment="Framed" brackets-onmouseover="true" highlight-keywords="true" keywords-color="#FFF3D2" keywords-highlightment="Filled" keywords-onmouseover="true" whereami="false" tab-size="4" use-spaces="true" indent-size="4" automatic-indent="true"/>
     </body>
   </display>
-  <syntax>
-    <body>
-      <scinotes-syntax highlight="true" hightlight-brackets="true" tab-size="4" use-spaces="true" indent-size="4" automatic-indent="true"/>
-    </body>
-  </syntax>
   <autosave>
     <body>
-      <scinotes-autosave enable="true" save-every="5" save-untitled="true" automatic-delete="true" append-flag="true" append-with="~" replace-with="tmp" source-flag="true" single-directory=""/>
+      <scinotes-autosave enable="true" save-every="5" automatic-delete="true" append-with="~" replace-with="tmp" source-flag="true" single-directory=""/>
     </body>
   </autosave>
-</scinotes>
\ No newline at end of file
+</scinotes>
index 080750c..36d09c2 100644 (file)
@@ -1,54 +1,97 @@
 <?xml version='1.0' encoding='utf-8'?>\r
 <xsl:stylesheet version ="1.0"\r
-                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
-                >\r
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\r
 \r
   <xsl:template match="scinotes-preferences">\r
-    <Title text="Open files in Scinotes">\r
-      <xsl:call-template name="BooleanCheckBox">\r
-        <xsl:with-param name="attr-name" select="'restart-reopen'"/>\r
-        <xsl:with-param name="text" select="'On restart reopen files from previous scilab session'"/>\r
-      </xsl:call-template>\r
-    </Title>\r
-    <Title text="Automatic File changes">\r
-      <xsl:call-template name="BooleanCheckBox">\r
-        <xsl:with-param name="attr-name" select="'reload-unedited'"/>\r
-        <xsl:with-param name="text" select="'Reload unedited files that have been externally modified'"/>\r
-      </xsl:call-template>\r
-\r
-      <xsl:call-template name="BooleanCheckBox">\r
-        <xsl:with-param name="attr-name" select="'add-line-termination'"/>\r
-        <xsl:with-param name="text" select="'Add line termination at end of file.'"/>\r
-      </xsl:call-template>\r
+    <Title text="Editor">\r
+      <VBox>\r
+        <HBox>\r
+          <xsl:call-template name="BooleanCheckBox">\r
+            <xsl:with-param name="text" select="'Use SciNotes'"/>\r
+            <xsl:with-param name="attr-name" select="'scinotes'"/>\r
+          </xsl:call-template>\r
+          <Glue/>\r
+        </HBox>\r
+        <xsl:variable name="enable">\r
+          <xsl:choose>\r
+            <xsl:when test="@scinotes='true'">\r
+              <xsl:text>false</xsl:text>\r
+            </xsl:when>\r
+            <xsl:otherwise>\r
+              <xsl:text>true</xsl:text>\r
+            </xsl:otherwise>\r
+          </xsl:choose>\r
+        </xsl:variable>\r
+        <Grid>\r
+         <Radiobutton value="{@external-cmd}" expected-value="true" listener="ActionListener" text="External editor: " gridx="1" gridy="1" fill="none" weightx="0" anchor="west" enable="{$enable}">\r
+           <actionPerformed choose="external-cmd">\r
+             <xsl:call-template name="context"/>\r
+           </actionPerformed>\r
+         </Radiobutton>\r
+          <FileSelector gridx="2" gridy="1" weightx="1" anchor="above_baseline"\r
+                        listener="EntryListener"\r
+                        href="{@cmd}"\r
+                        dir-selection="false">\r
+           <xsl:attribute name="enable">\r
+             <xsl:if test="@scinotes='false' and @external-cmd='true'">\r
+               <xsl:text>true</xsl:text>\r
+             </xsl:if>\r
+           </xsl:attribute>\r
+           <entryChanged choose="cmd">\r
+              <xsl:call-template name="context"/>\r
+            </entryChanged>\r
+          </FileSelector>\r
+         <Radiobutton value="{@external-cmd}" expected-value="false" listener="ActionListener" text="Scilab macro: " gridx="1" gridy="2" fill="none" weightx="0" anchor="west" enable="{$enable}">\r
+           <actionPerformed choose="external-cmd">\r
+             <xsl:call-template name="context"/>\r
+           </actionPerformed>\r
+         </Radiobutton>\r
+          <Entry gridx="2" gridy="2" weightx="1" anchor="above_baseline"\r
+                        listener="EntryListener"\r
+                        text="{@cmd}">\r
+           <xsl:attribute name="enable">\r
+             <xsl:if test="@scinotes='false' and @external-cmd='false'">\r
+               <xsl:text>true</xsl:text>\r
+             </xsl:if>\r
+           </xsl:attribute>\r
+            <entryChanged choose="macro">\r
+              <xsl:call-template name="context"/>\r
+            </entryChanged>\r
+          </Entry>\r
+       </Grid>\r
+      </VBox>\r
     </Title>\r
-    <Title text="Recently used file list">\r
+    <VSpace height="10"/>\r
+    <Title text="SciNotes General settings">\r
       <Grid>\r
-        <Label text="Number of entries:"/>\r
-        <Panel gridx="2">\r
-          <xsl:call-template name="Select">\r
-            <xsl:with-param name="among">\r
-              <option number-of-entries="1"/>\r
-              <option number-of-entries="2"/>\r
-              <option number-of-entries="3"/>\r
-              <option number-of-entries="4"/>\r
-              <option number-of-entries="5"/>\r
-              <option number-of-entries="6"/>\r
-              <option number-of-entries="7"/>\r
-              <option number-of-entries="8"/>\r
-              <option number-of-entries="9"/>\r
-              <option number-of-entries="10"/>\r
-              <option number-of-entries="20"/>\r
-              <option number-of-entries="40"/>\r
-              <option number-of-entries="80"/>\r
-            </xsl:with-param>\r
+        <Panel gridx="1" gridy="1" gridwidth="3">\r
+          <xsl:call-template name="BooleanCheckBox">\r
+            <xsl:with-param name="attr-name" select="'restart-reopen'"/>\r
+            <xsl:with-param name="text" select="'Restore previous session on start-up'"/>\r
           </xsl:call-template>\r
         </Panel>\r
-      </Grid>\r
-    </Title>\r
-    <Title text="File encoding">\r
-      <Grid>\r
-        <Label text="File encoding:"/>\r
-        <Panel gridx="2">\r
+        <Panel gridx="1" gridy="2" gridwidth="3">\r
+          <xsl:call-template name="BooleanCheckBox">\r
+            <xsl:with-param name="attr-name" select="'add-line-termination'"/>\r
+            <xsl:with-param name="text" select="'Add carriage return at the end of the file.'"/>\r
+          </xsl:call-template>\r
+        </Panel>\r
+        <Label gridx="1" gridy="3" weightx="0" text="Number of recently opened files to display: "/>\r
+        <Panel gridx="2" gridy="3" gridheight="2" fill="both"/>\r
+        <NumericalSpinner gridx="3"\r
+                          gridy="3"\r
+                          weightx="0"\r
+                          min-value = "0"\r
+                          increment = "1"\r
+                          length = "4"\r
+                          listener = "ActionListener"\r
+                          value = "{@number-of-recently-open}">\r
+          <actionPerformed choose="number-of-recently-open">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </NumericalSpinner>\r
+        <Label gridx="1" gridy="4" weightx="0" text="Default file encoding: "/>\r
+        <Panel gridx="3" gridy="4">\r
           <xsl:call-template name="Select">\r
             <xsl:with-param name="among">\r
               <option encoding="utf-8"/>\r
             </xsl:with-param>\r
           </xsl:call-template>\r
         </Panel>\r
-      </Grid>\r
-    </Title>\r
-    <Title text="End of file">\r
-      <Grid>\r
-        <Label text="End of line:"/>\r
-        <Panel gridx="2">\r
+        <Label gridx="1" gridy="5" weightx="0" text="Default End-Of-Line: "/>\r
+        <Panel gridx="3" gridy="5">\r
           <xsl:call-template name="Select">\r
             <xsl:with-param name="among">\r
-              <option eol="Unix(LF)"/>\r
-              <option eol="Windows/Dos(CR+LF)"/>\r
-              <option eol="Mac Classic(CR)"/>\r
+              <option eol="Unix (LF)"/>\r
+              <option eol="Windows (CR+LF)"/>\r
+              <option eol="Mac OS (CR)"/>\r
             </xsl:with-param>\r
           </xsl:call-template>\r
         </Panel>\r
 \r
   <xsl:template match="scinotes-display">\r
     <Title text="General display options">\r
-      <VBox>\r
-        <VSpace height="20"/>\r
-        <HBox>\r
-          <xsl:call-template name="BooleanCheckBox">\r
-            <xsl:with-param name="attr-name" select="'highlight-current-line'"/>\r
-            <xsl:with-param name="text">\r
-              <xsl:choose>\r
-                <xsl:when test="@highlight-current-line='true'">Highlight current line with</xsl:when>\r
-                <xsl:otherwise>Highlight current line</xsl:otherwise>\r
-              </xsl:choose>\r
+      <Grid>\r
+       <Checkbox checked="{@highlight-current-line}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight current line: " gridx="1" gridy="1" fill="none" weightx="0" anchor="west">\r
+         <actionPerformed choose="highlight-current-line">\r
+           <xsl:call-template name="context"/>\r
+         </actionPerformed>\r
+       </Checkbox>\r
+       <Panel gridx="2" gridy="1" weightx="1"/>\r
+       <Panel gridx="3" gridy="1" weightx="1"/>\r
+       <Color color="{@current-line-color}" listener="ActionListener" gridx="4" gridy="1" weightx="0" enable="{@highlight-current-line}">\r
+         <actionPerformed choose="current-line-color">\r
+           <xsl:call-template name="context"/>\r
+         </actionPerformed>\r
+       </Color>\r
+       <Checkbox checked="{@show-line-numbers}" selected-value="true" unselected-value="false" listener="ActionListener" text="Show line numbers: " gridx="1" gridy="2" fill="none" weightx="0" anchor="west">\r
+         <actionPerformed choose="show-line-numbers">\r
+           <xsl:call-template name="context"/>\r
+         </actionPerformed>\r
+       </Checkbox>\r
+       <Radiobutton value="{@whereami}" expected-value="true" listener="ActionListener" text="Whereami compatible" gridx="2" gridy="2" fill="none" weightx="0" anchor="west" enable="{@show-line-numbers}">\r
+         <actionPerformed choose="whereami">\r
+           <xsl:call-template name="context"/>\r
+         </actionPerformed>\r
+       </Radiobutton>\r
+       <Radiobutton value="{@whereami}" expected-value="false" listener="ActionListener" text="Normal" gridx="3" gridy="2" gridwidth="2" fill="none" weightx="0" anchor="west" enable="{@show-line-numbers}">\r
+         <actionPerformed choose="whereami">\r
+           <xsl:call-template name="context"/>\r
+         </actionPerformed>\r
+       </Radiobutton>\r
+       <Checkbox checked="{@wrap-lines}" selected-value="true" unselected-value="false" listener="ActionListener" text="Wrap lines" gridx="1" gridy="3" fill="none" weightx="0" anchor="west">\r
+         <actionPerformed choose="wrap-lines">\r
+           <xsl:call-template name="context"/>\r
+         </actionPerformed>\r
+       </Checkbox>\r
+      </Grid>\r
+    </Title>\r
+    <VSpace height="10"/>\r
+    <Title text="Keywords">\r
+        <Grid>\r
+         <Checkbox checked="{@keywords-colorization}" selected-value="true" unselected-value="false" listener="ActionListener" text="Enable keywords colorization" gridx="1" gridy="1" fill="none" weightx="0" anchor="west">\r
+           <actionPerformed choose="keywords-colorization">\r
+             <xsl:call-template name="context"/>\r
+           </actionPerformed>\r
+         </Checkbox>\r
+         <Panel gridx="2" gridy="1" weightx="1"/>\r
+         <Link gridx="3" gridy="1" weightx="0" listener="MouseListener" text="Set syntax Colors" enable="{@keywords-colorization}">\r
+           <mouseClicked set="path" value="3/" context="/" enable="{@keywords-colorization}"/>\r
+         </Link>\r
+         <Checkbox checked="{@highlight-brackets}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight corresponding brackets" gridx="1" gridy="2" fill="none" weightx="0" anchor="west">\r
+           <actionPerformed choose="highlight-brackets">\r
+             <xsl:call-template name="context"/>\r
+           </actionPerformed>\r
+         </Checkbox>\r
+         <Grid gridx="1" gridy="3" gridwidth="3" ipadx="10">\r
+           <Label gridx="1" gridy="1" weightx="0" text="Color: " enable="{@highlight-brackets}"/>        \r
+           <Color color="{@brackets-color}" listener="ActionListener" gridx="2" gridy="1" weightx="0" enable="{@highlight-brackets}">\r
+             <actionPerformed choose="brackets-color">\r
+               <xsl:call-template name="context"/>\r
+             </actionPerformed>\r
+           </Color>\r
+           <Panel gridx="3" gridy="1" weightx="1"/>\r
+           <Checkbox checked="{@brackets-onmouseover}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight on mouse over" gridx="4" gridy="1" fill="none" weightx="0" anchor="west" enable="{@highlight-brackets}">\r
+             <actionPerformed choose="brackets-onmouseover">\r
+               <xsl:call-template name="context"/>\r
+             </actionPerformed>\r
+           </Checkbox>\r
+           <Panel gridx="5" gridy="1" weightx="1"/>\r
+           <Label gridx="6" gridy="1" weightx="0" text="Style: " enable="{@highlight-brackets}"/>        \r
+           <Panel gridx="7" gridy="1" weightx="0">\r
+             <xsl:call-template name="Select">\r
+               <xsl:with-param name="among">\r
+                 <option brackets-highlightment="Filled"/>\r
+                 <option brackets-highlightment="Framed"/>\r
+                 <option brackets-highlightment="Underlined"/>\r
+               </xsl:with-param>\r
+               <xsl:with-param name="enable" select="@highlight-brackets" />\r
+             </xsl:call-template>\r
+           </Panel>\r
+         </Grid>\r
+         <Checkbox checked="{@highlight-keywords}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight corresponding keywords (e.g. if ... end)" gridx="1" gridy="4" fill="none" weightx="0" anchor="west">\r
+           <actionPerformed choose="highlight-keywords">\r
+             <xsl:call-template name="context"/>\r
+           </actionPerformed>\r
+         </Checkbox>\r
+         <Grid gridx="1" gridy="5" gridwidth="3" ipadx="10">\r
+           <Label gridx="1" gridy="1" weightx="0" text="Color: " enable="{@highlight-keywords}"/>        \r
+           <Color color="{@keywords-color}" listener="ActionListener" gridx="2" gridy="1" weightx="0" enable="{@highlight-keywords}">\r
+             <actionPerformed choose="keywords-color">\r
+               <xsl:call-template name="context"/>\r
+             </actionPerformed>\r
+           </Color>\r
+           <Panel gridx="3" gridy="1" weightx="1"/>\r
+           <Checkbox checked="{@keywords-onmouseover}" selected-value="true" unselected-value="false" listener="ActionListener" text="Highlight on mouse over" gridx="4" gridy="1" fill="none" weightx="0" anchor="west" enable="{@highlight-keywords}">\r
+             <actionPerformed choose="keywords-onmouseover">\r
+               <xsl:call-template name="context"/>\r
+             </actionPerformed>\r
+           </Checkbox>\r
+           <Panel gridx="5" gridy="1" weightx="1"/>\r
+           <Label gridx="6" gridy="1" weightx="0" text="Style: " enable="{@highlight-keywords}"/>        \r
+           <Panel gridx="7" gridy="1" weightx="0">\r
+             <xsl:call-template name="Select">\r
+               <xsl:with-param name="among">\r
+                 <option keywords-highlightment="Filled"/>\r
+                 <option keywords-highlightment="Framed"/>\r
+               </xsl:with-param>\r
+               <xsl:with-param name="enable" select="@highlight-keywords" />\r
+             </xsl:call-template>\r
+           </Panel>\r
+         </Grid>\r
+       </Grid>\r
+    </Title>\r
+    <VSpace height="10"/>\r
+    <Title text="Tabulation &amp; Indentation">\r
+      <Grid>\r
+        <Label text="Tabulation size:" gridx="1" gridy="1" weightx="0"/>\r
+       <NumericalSpinner gridx="2"\r
+                          gridy="1"\r
+                         weightx="0"\r
+                          min-value = "1"\r
+                          increment = "1"\r
+                          length = "3"\r
+                          listener = "ActionListener"\r
+                          value = "{@tab-size}">\r
+          <actionPerformed choose="tab-size">\r
+            <xsl:call-template name="context"/>\r
+          </actionPerformed>\r
+        </NumericalSpinner>\r
+        <Panel gridx="3" gridy="1" weightx="1"/>\r
+       <Checkbox checked="{@use-spaces}" selected-value="true" unselected-value="false" listener="ActionListener" text="Use space" gridx="4" gridy="1" fill="none" weightx="0" anchor="west">\r
+         <actionPerformed choose="use-spaces">\r
+           <xsl:call-template name="context"/>\r
+         </actionPerformed>\r
+       </Checkbox>\r
+       <Checkbox checked="{@automatic-indent}" selected-value="true" unselected-value="false" listener="ActionListener" text="Enable auto indentation" gridx="1" gridy="2" fill="none" weightx="0" anchor="west">\r
+         <actionPerformed choose="use-spaces">\r
+           <xsl:call-template name="context"/>\r
+         </actionPerformed>\r
+       </Checkbox>\r
+        <Label gridy="3" text="Indent size:"/>\r
+        <Panel gridy="3" gridx="2" >\r
+          <xsl:call-template name="Select">\r
+            <xsl:with-param name="among">\r
+              <option indent-size="2"/>\r
+              <option indent-size="4"/>\r
+              <option indent-size="8"/>\r
             </xsl:with-param>\r
           </xsl:call-template>\r
-          <xsl:if test="@highlight-current-line='true'">\r
-            <Color color="{@current-line-color}" listener="ActionListener">\r
-              <actionPerformed choose="current-line-color">\r
-                <xsl:call-template name="context"/>\r
-              </actionPerformed>\r
-            </Color>\r
-          </xsl:if>\r
-          <Glue/>\r
-        </HBox>\r
-        <VSpace height="20"/>\r
-        <HBox>\r
-          <xsl:call-template name="BooleanCheckBox">\r
-            <xsl:with-param name="attr-name" select="'show-line-numbers'"/>\r
-            <xsl:with-param name="text" select="'Show line numbers'"/>\r
-          </xsl:call-template>\r
-          <Glue/>\r
-        </HBox>\r
-        <VSpace height="20"/>\r
-        <HBox>\r
-          <xsl:call-template name="BooleanCheckBox">\r
-            <xsl:with-param name="attr-name" select="'wrap-lines'"/>\r
-            <xsl:with-param name="text" select="'Wrap line'"/>\r
-          </xsl:call-template>\r
-          <Glue/>\r
-        </HBox>\r
-        <VSpace height="20"/>\r
-        <Grid insets="large" anchor="west">\r
-          <Label text="View"/>\r
-          <Link gridx="2" listener="MouseListener" text="custom font">\r
-            <mouseClicked set="path" value="2/" context="/"/>\r
-          </Link>\r
-          <Label gridx="3" text="preferences to change Scinotes fonts."/>\r
-        </Grid>\r
-\r
-      </VBox>\r
+        </Panel>\r
+      </Grid>\r
     </Title>\r
-    <VSpace height="200"/>\r
   </xsl:template>\r
 \r
-  <xsl:template match="scinotes-syntax">\r
-    <Title text="Syntax">\r
-      <VBox>\r
-        <VSpace height="20"/>\r
-        <HBox>\r
-          <xsl:call-template name="BooleanCheckBox">\r
-            <xsl:with-param name="attr-name" select="'highlight'"/>\r
-            <xsl:with-param name="text" select="'Enable syntax highlighting'"/>\r
-          </xsl:call-template>\r
-          <xsl:if test="@highlight='true'">\r
-            <HSpace width="30"/>\r
-            <Link listener="MouseListener" text="Set syntax Colors">\r
-              <mouseClicked set="path" value="3/" context="/"/>\r
-            </Link>\r
-          </xsl:if>\r
-          <Glue/>\r
-        </HBox>\r
-        <VSpace height="20"/>\r
-        <HBox>\r
-          <xsl:call-template name="BooleanCheckBox">\r
-            <xsl:with-param name="attr-name" select="'hightlight-brackets'"/>\r
-            <xsl:with-param name="text" select="'Highlight corresponding brackets'"/>\r
-          </xsl:call-template>\r
-          <Glue/>\r
-        </HBox>\r
-      </VBox>\r
-    </Title>\r
+  <!--xsl:template match="scinotes-syntax">\r
     <VSpace height="20"/>\r
     <Title text="Tabs &amp; Indents">\r
       <Grid ipady="30" insets="large">\r
         </HBox>\r
       </Grid>\r
     </Title>\r
-  </xsl:template>\r
+  </xsl:template-->\r
 \r
   <xsl:template match="scinotes-autosave">\r
     <HBox>\r
             <xsl:call-template name="BooleanCheckBox">\r
               <xsl:with-param name="attr-name" select="'automatic-delete'"/>\r
             </xsl:call-template>\r
-            Automatically delete autosave files\r
+            Delete automatically saved files\r
             <Glue/>\r
           </HBox>\r
         </Title>\r
-        <Title text="File name">\r
+        <Title text="Filename">\r
           <Grid>\r
             <Panel>\r
               <xsl:call-template name="BooleanRadio">\r
                 <xsl:with-param name="text" select="'Single directory:'"/>\r
               </xsl:call-template>\r
             </Panel>\r
-            <File gridx="2" gridy="2" enable="{@source-flag='false'}" href="{@single-directory}" mask="*"\r
-                  desc="Choose an autosave directory"\r
-                  listener="ActionListener">\r
+            <FileSelector gridx="2" gridy="2" enable="{@source-flag='false'}" href="{@single-directory}" mask="*"\r
+                          desc="Choose an autosave directory"\r
+                          dir-selection = "true"\r
+                          listener="DocumentListener">\r
               <actionPerformed choose="single-directory">\r
                 <xsl:call-template name="context"/>\r
               </actionPerformed>\r
-            </File>\r
+            </FileSelector>\r
           </Grid>\r
         </Title>\r
       </xsl:when>\r
index bbcaea7..48ebbbd 100644 (file)
 <?xml version="1.0" encoding="UTF-8"?>
 
 <Configuration>
-
+  
   <MenuBar>
     <menu label="File" mnemonic="F">
-      <menuitem action="NewAction" label="New"/>
-      <menuitem action="OpenAction" label="Open"/>
-      <menuitem action="RecentFileAction" label="Open recent"/>
+      <menuitem action="scinotes-new" label="New"/>
+      <menuitem action="scinotes-open" label="Open"/>
+      <menuitem action="scinotes-recent" label="Open recent"/>
       <separator/>
-      <menuitem action="RegisterFavoriteDirsAction" label="Working directories;Add a directory;Remove last directory"/>
-      <menuitem action="OpenFileInAction" label="Open file in ..."/>
-      <menuitem action="SaveFileInAction" label="Save file in ..."/>
+      <menuitem action="scinotes-register-favorite-dir" label="Working directories;Add a directory;Remove last directory"/>
+      <menuitem action="scinotes-open-file-in" label="Open file in ..."/>
+      <menuitem action="scinotes-save-file-in" label="Save file in ..."/>
       <separator/>
-      <menuitem action="ReloadAction" label="Reload"/>
-      <menuitem action="RestoreOpenedFilesAction" label="Restore opened files on start-up"/>
-      <menuitem action="OpenSourceFileOnKeywordAction" label="Open function source file"/>
-      <menuitem action="OpenURLAction" label="Open URL"/>
+      <menuitem action="scinotes-reload" label="Reload"/>
+      <menuitem action="scinotes-restore-startup" label="Restore opened files on start-up"/>
+      <menuitem action="scinotes-open-source" label="Open function source file"/>
+      <menuitem action="scinotes-open-url" label="Open URL"/>
       <separator/>
-      <menuitem action="SaveAction" label="Save"/>
-      <menuitem action="SaveAsAction" label="Save as"/>
-      <menuitem action="SaveAllAction" label="Save All"/>
-      <menuitem action="OverwriteAction" label="Overwrite"/>
+      <menuitem action="scinotes-save" label="Save"/>
+      <menuitem action="scinotes-save-as" label="Save as"/>
+      <menuitem action="scinotes-save-all" label="Save All"/>
+      <menuitem action="scinotes-overwrite" label="Overwrite"/>
       <separator/>
-      <menuitem action="ExportAction" label="Export"/>
+      <menuitem action="scinotes-export" label="Export"/>
       <separator/>
-      <menuitem action="PageSetupAction" label="Page Setup"/>
-      <menuitem action="PrintPreviewAction" label="Print Preview"/>
-      <menuitem action="PrintAction" label="Print"/>
+      <menuitem action="scinotes-page-setup" label="Page Setup"/>
+      <menuitem action="scinotes-print-preview" label="Print Preview"/>
+      <menuitem action="scinotes-print" label="Print"/>
       <separator/>
-      <menuitem action="CloseAction" label="Close"/>
-      <menuitem action="CloseAllAction" label="Close All"/>
-      <menuitem action="CloseAllButThisAction" label="Close All But This"/>
+      <menuitem action="scinotes-close" label="Close"/>
+      <menuitem action="scinotes-close-all" label="Close All"/>
+      <menuitem action="scinotes-close-all-but" label="Close All But This"/>
       <separator/>
-      <menuitem action="ExitAction" label="Exit"/>
+      <menuitem action="scinotes-exit" label="Exit"/>
     </menu>
-
+    
     <menu label="Edit" mnemonic="E">
-      <menuitem action="UndoAction" label="Undo"/>
-      <menuitem action="RedoAction" label="Redo"/>
+      <menuitem action="scinotes-undo" label="Undo"/>
+      <menuitem action="scinotes-redo" label="Redo"/>
       <separator/>
-      <menuitem action="CutAction" label="Cut"/>
-      <menuitem action="CopyAsHTMLAction" label="Copy"/>
-      <menuitem action="CopyAsHTMLWithLineNumberAction" label="Copy as HTML with line number"/>
-      <menuitem action="PasteAction" label="Paste"/>
-      <menuitem action="DeleteAction" label="Delete"/>
+      <menuitem action="scinotes-cut" label="Cut"/>
+      <menuitem action="scinotes-copy" label="Copy"/>
+      <menuitem action="scinotes-copy-with-lines" label="Copy as HTML with line number"/>
+      <menuitem action="scinotes-paste" label="Paste"/>
+      <menuitem action="scinotes-delete" label="Delete"/>
       <separator/>
       <menu label="Columns actions">
-       <menuitem action="PasteColumnAction" label="Paste Column"/>
-       <menuitem action="RepeatSelectionOnColumnAction" label="Repeat on the Column"/>
+        <menuitem action="scinotes-paste-column" label="Paste Column"/>
+        <menuitem action="scinotes-repeat-column" label="Repeat on the Column"/>
       </menu>
       <separator/>
-      <menuitem action="SelectAllAction" label="Select All"/>
-      <menuitem action="SelectBlockAction" label="Select current block"/>
+      <menuitem action="scinotes-select-all" label="Select All"/>
+      <menuitem action="scinotes-select-block" label="Select current block"/>
       <separator/>
       <menu label="Search" mnemonic="H">
-       <menuitem action="FindAction" label="Find/Replace"/>
-       <menuitem action="FindNextAction" label="Find Next"/>
-       <menuitem action="FindPreviousAction" label="Find Previous"/>
-       <menuitem action="IncrementalSearchAction" label="Incremental Search"/>
-       <separator/>
-       <menuitem action="SearchFilesAction" label="Find files"/>
-       <menuitem action="SearchWordInFilesAction" label="Find word in files"/>
-       <separator/>
-       <menuitem action="SetAnchorAction" label="Set anchor"/>
-       <menuitem action="GotoNextAnchorAction" label="Go to next anchor"/>
-       <menuitem action="GotoPreviousAnchorAction" label="Go to previous anchor"/>
-       <menuitem action="RemoveAnchorAction" label="Remove anchor"/>
-       <separator/>
-       <menuitem action="CodeNavigatorAction" label="Code Navigator"/>
-      </menu> 
+        <menuitem action="scinotes-find" label="Find/Replace"/>
+        <menuitem action="scinotes-find-next" label="Find Next"/>
+        <menuitem action="scinotes-find-previous" label="Find Previous"/>
+        <menuitem action="scinotes-incremental-search" label="Incremental Search"/>
+        <separator/>
+        <menuitem action="scinotes-search-files" label="Find files"/>
+        <menuitem action="scinotes-word-file" label="Find word in files"/>
+        <separator/>
+        <menuitem action="scinotes-set-anchor" label="Set anchor"/>
+        <menuitem action="scinotes-next-anchor" label="Go to next anchor"/>
+        <menuitem action="scinotes-previous-anchor" label="Go to previous anchor"/>
+        <menuitem action="scinotes-remove-anchor" label="Remove anchor"/>
+        <separator/>
+        <menuitem action="scinotes-code-navigator" label="Code Navigator"/>
+      </menu>
+       
     </menu>
-
+    
     <menu label="Format" mnemonic="P">
-      <menuitem action="TabifyAction" label="Shift Right"/>
-      <menuitem action="UnTabifyAction" label="Shift Left"/>
-      <menuitem action="ConfigTabulationsAction" label="Configure Tabulation"/>
+      <menuitem action="scinotes-tabify" label="Shift Right"/>
+      <menuitem action="scinotes-untabify" label="Shift Left"/>
+      <!--menuitem action="ConfigTabulationsAction" label="Configure Tabulation"/-->
       <separator/>
-      <menuitem action="HorizontalWrapAction" label="Horizontal wrapping"/>
+      <!--menuitem action="HorizontalWrapAction" label="Horizontal wrapping"/-->
       <separator/>
-      <menuitem action="IndentAction" label="Correct Indentation"/>
-      <menuitem action="RemoveTrailingWhiteAction" label="Remove trailing spaces"/>
-      <menuitem action="GenerateHelpFromFunctionAction" label="Generate comments for help_from_sci"/>
+      <menuitem action="scinotes-indent" label="Correct Indentation"/>
+      <menuitem action="scinotes-remove-whites" label="Remove trailing spaces"/>
+      <menuitem action="scinotes-help-prototype" label="Generate comments for help_from_sci"/>
       <separator/>
-      <menuitem action="CommentAction" label="Comment Selection"/>
-      <menuitem action="UnCommentAction" label="Uncomment Selection"/>
+      <menuitem action="scinotes-comment" label="Comment Selection"/>
+      <menuitem action="scinotes-uncomment" label="Uncomment Selection"/>
       <separator/>
       <menu label="Change the case">
-       <menuitem action="ToLowerCaseAction" label="Make Selection Lowercase"/>
-       <menuitem action="ToUpperCaseAction" label="Make Selection Uppercase"/>
-       <menuitem action="CapitalizeAction" label="Capitalize Selection;Capitalize character"/>
+        <menuitem action="scinotes-tolowercase" label="Make Selection Lowercase"/>
+        <menuitem action="scinotes-touppercase" label="Make Selection Uppercase"/>
+        <menuitem action="scinotes-capitalize" label="Capitalize Selection;Capitalize character"/>
       </menu>
       <separator/>
-      <menuitem action="DoubleQuoteStringAction" label="Single to double quote strings"/>
+      <menuitem action="scinotes-double-quote" label="Single to double quote strings"/>
     </menu>
-
+    
     <menu label="Options">
-      <menuitem action="EncodingAction" label="Current file encoding"/>
-      <menuitem action="DefaultEncodingAction" label="Default SciNotes file encoding;UTF-8;Windows 1252 (ANSI);ISO-8859-1"/>
-      <menuitem action="EndOfLineAction" label="Line Endings"/>
-      <separator/>
-      <menu label="Auto-completion on">
-       <menuitem action="ActivateHelpOnTypingForOpenersAction" label="(, [, ..."/>
-       <menuitem action="ActivateHelpOnTypingForKeywordsAction" label="if, function, ..."/>
-      </menu>
+      <menuitem action="scinotes-encoding" label="Current file encoding"/>
+      <menuitem action="scinotes-default-encoding" label="Default SciNotes file encoding;UTF-8;Windows 1252 (ANSI);ISO-8859-1"/>
+      <menuitem action="scinotes-eof" label="Line Endings"/>
       <separator/>
-      <menuitem action="LineNumbersAction" label="Line numbering;Off;Normal;Whereami compatible"/>
-      <menuitem action="HighlightCurrentLineAction" label="Highlight current line"/>
+      <menuitem action="scinotes-line-numbering" label="Line numbering;Off;Normal;Whereami compatible"/>
+      <!--menuitem action="HighlightCurrentLineAction" label="Highlight current line"/>
       <menuitem action="AutoIndentAction" label="Enable Auto Reformat"/>
       <separator/>
-      <menuitem action="SuppressCommentsAction" label="Suppress comments when executing selection"/>
+      <menuitem action="SuppressCommentsAction" label="Suppress comments when executing selection"/-->
     </menu>
-
+    
     <menu label="Window" mnemonic="N">
-      <menuitem action="OpenTabInNewWindowAction" label="Copy tab in new window"/>
-      <menuitem action="CCloseTabInNewWindowAction" label="Detach tab in new window"/>
+      <menuitem action="scinotes-clone-current" label="Copy tab in new window"/>
+      <menuitem action="scinotes-export-current" label="Detach tab in new window"/>
       <separator/>
-      <menuitem action="CopySelectionInNewTabAction" label="Copy selection in a new tab"/>
+      <menuitem action="scinotes-selection-new-tab" label="Copy selection in a new tab"/>
       <separator/>
-      <menuitem action="SplitAction" label="Split View;Off;Horizontally;Vertically"/>
-  </menu>
-
+      <menuitem action="scinotes-split" label="Split View;Off;Horizontally;Vertically"/>
+    </menu>
+    
     <menu label="Execute" mnemonic="X">
-      <menuitem action="ExecuteFileIntoScilabAction" label="... file with no echo"/>
-      <menuitem action="LoadIntoScilabAction" label="... file with echo"/>
-      <menuitem action="EvaluateSelectionAction" label="... the selection with echo;... until the caret, with echo"/>
+      <menuitem action="scinotes-execute-scilab" label="... file with no echo"/>
+      <menuitem action="scinotes-load-scilab" label="... file with echo"/>
+      <menuitem action="scinotes-evaluate-selection" label="... the selection with echo;... until the caret, with echo"/>
       <separator/>
-      <menuitem action="SaveAndExecuteFileAction" label="Save and execute"/>
-      <menuitem action="SaveAndExecuteAllFilesAction" label="Save and execute all files"/>
+      <menuitem action="scinotes-save-execute" label="Save and execute"/>
+      <menuitem action="scinotes-save-execute-all" label="Save and execute all files"/>
     </menu>
-
+    
     <menu label="?">
-      <menuitem action="HelpAction" label="SciNotes help"/>
-      <menuitem action="HelpOnKeywordAction" label="Help on ;Help on selection"/>
-      <menuitem action="AboutAction" label="About"/>
+      <menuitem action="scinotes-help" label="SciNotes help"/>
+      <menuitem action="scinotes-help-keyword" label="Help on ;Help on selection"/>
+      <menuitem action="scinotes-about" label="About"/>
     </menu>
   </MenuBar>
-
+  
   <RightClickMenu>
-    <menuitem action="EvaluateSelectionAction" label="Evaluate Selection with echo;Evaluate until the caret, with echo"/>
-    <menuitem action="CopySelectionInNewTabAction" label="Copy selection in a new tab"/>
-    <menuitem action="SciNotesCompletionAction" label="Complete"/>
+    <menuitem action="scinotes-evaluate-selection" label="Evaluate Selection with echo;Evaluate until the caret, with echo"/>
+    <menuitem action="scinotes-selection-new-tab" label="Copy selection in a new tab"/>
+    <menuitem action="scinotes-completion" label="Complete"/>
     <separator/>
-    <menuitem action="SelectAllAction" label="Select All"/>
-    <menuitem action="SelectBlockInPopupAction" label="Select current block"/>
-    <menuitem action="CopyAsHTMLAction" label="Copy"/>
-    <menuitem action="CutAction" label="Cut"/>
-    <menuitem action="PasteAction" label="Paste"/>
-    <menuitem action="PasteColumnAction" label="Paste Column"/>
+    <menuitem action="scinotes-select-all" label="Select All"/>
+    <menuitem action="scinotes-select-block" label="Select current block"/>
+    <menuitem action="scinotes-copy" label="Copy"/>
+    <menuitem action="scinotes-cut" label="Cut"/>
+    <menuitem action="scinotes-paste" label="Paste"/>
+    <menuitem action="scinotes-paste-column" label="Paste Column"/>
     <separator/>
-    <menuitem action="IndentAction" label="Correct Indentation"/>    
+    <menuitem action="scinotes-indent" label="Correct Indentation"/>
+     
     <separator/>
-    <menuitem action="CopyAsHTMLWithLineNumberAction" label="Copy as HTML with line number"/>
+    <menuitem action="scinotes-copy-with-lines" label="Copy as HTML with line number"/>
     <separator/>
-    <menuitem action="HelpOnKeywordInPopupAction" label="Help on ;Help on selection"/>
-    <menuitem action="OpenSourceFileOnKeywordAction" label="Open function source file"/>
-    <menuitem action="OpenURLAction" label="Open URL"/>
+    <menuitem action="scinotes-help-keyword-popup" label="Help on ;Help on selection"/>
+    <menuitem action="scinotes-open-source" label="Open function source file"/>
+    <menuitem action="scinotes-open-url" label="Open URL"/>
   </RightClickMenu>
-
+  
   <ToolBar>
-    <button action="NewAction" tooltip="New" icon="document-new"/>
-    <button action="OpenAction" tooltip="Open" icon="document-open"/>
-
+    <button action="scinotes-new" tooltip="New" icon="document-new"/>
+    <button action="scinotes-open" tooltip="Open" icon="document-open"/>
+    
     <!-- The second token of the button OpenFileInAction is the full path of the directory
          where to open files.
          The shortcuts SCI or MODULES can be used (not in path but alone) -->
-    <button action="OpenFileInAction" tooltip="Open in ;MODULES" icon="document-open-sci"/>
-
+    <button action="scinotes-open-file-in" tooltip="Open in ;MODULES" icon="document-open-sci"/>
+    
     <separator/>
-    <button action="SaveAction" tooltip="Save" icon="media-floppy"/>
-    <button action="SaveAsAction" tooltip="Save as" icon="document-save-as"/>
+    <button action="scinotes-save" tooltip="Save" icon="media-floppy"/>
+    <button action="scinotes-save-as" tooltip="Save as" icon="document-save-as"/>
     <separator/>
-    <button action="PrintAction" tooltip="Print" icon="document-print"/>
+    <button action="scinotes-print" tooltip="Print" icon="document-print"/>
     <separator/>
-    <button action="UndoAction" tooltip="Undo" icon="edit-undo"/>
-    <button action="RedoAction" tooltip="Redo" icon="edit-redo"/>
+    <button action="scinotes-undo" tooltip="Undo" icon="edit-undo"/>
+    <button action="scinotes-redo" tooltip="Redo" icon="edit-redo"/>
     <separator/>
-    <button action="CutAction" tooltip="Cut" icon="edit-cut"/>
-    <button action="CopyAsHTMLAction" tooltip="Copy" icon="edit-copy"/>
-    <button action="PasteAction" tooltip="Paste" icon="edit-paste"/>
+    <button action="scinotes-cut" tooltip="Cut" icon="edit-cut"/>
+    <button action="scinotes-copy" tooltip="Copy" icon="edit-copy"/>
+    <button action="scinotes-paste" tooltip="Paste" icon="edit-paste"/>
     <separator/>
-    <button action="FindAction" tooltip="Find/Replace" icon="edit-find-replace"/>
-    <button action="IncrementalSearchAction" tooltip="Incremental Search" icon="go-bottom"/>
+    <button action="scinotes-find" tooltip="Find/Replace" icon="edit-find-replace"/>
+    <button action="scinotes-incremental-search" tooltip="Incremental Search" icon="go-bottom"/>
     <separator/>
-    <button action="ExecuteFileIntoScilabAction" tooltip="Execute" icon="media-playback-start"/>
-    <button action="SaveAndExecuteFileAction" tooltip="Execute" icon="save-and-execute"/>
-    <button action="SaveAndExecuteAllFilesAction" tooltip="Execute" icon="execute-all"/>
+    <button action="scinotes-execute-scilab" tooltip="Execute" icon="media-playback-start"/>
+    <button action="scinotes-save-execute" tooltip="Execute" icon="save-and-execute"/>
+    <button action="scinotes-save-execute-all" tooltip="Execute" icon="execute-all"/>
   </ToolBar>
-
+  
 </Configuration>
index 8be917d..73824f1 100644 (file)
@@ -16,6 +16,7 @@ import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.Rectangle;
 import java.awt.Shape;
+import java.util.Set;
 
 import javax.swing.text.BadLocationException;
 import javax.swing.text.DefaultHighlighter;
@@ -47,6 +48,8 @@ public class MatchingBlockManager {
     private boolean ocIncluded;
     private boolean kwIncluded;
     private boolean lr;
+    private boolean isOCMouseover;
+    private boolean isKWMouseover;
     private MouseOverMatcher mouseover;
 
     /**
@@ -104,15 +107,13 @@ public class MatchingBlockManager {
      * The contents between the matchings is highlighted.
      **/
     public void setPainterForOpenClose() {
-        Parameters param = ConfigSciNotesManager.getDefaultForMatcher("OpenCloseHighlighter");
-        if (param.inside) {
-            boolean b = param.type == ScilabKeywordsPainter.FILLED;
-            setPainterForOpenClose(b, param.included, param.color);
-        } else {
-            setPainterForOpenClose(param.type, param.color);
-        }
-        if (param.onmouseover) {
+        setPainterForOpenClose(SciNotesOptions.getSciNotesDisplay().bracketsHighlightment, SciNotesOptions.getSciNotesDisplay().bracketsColor);
+        if (SciNotesOptions.getSciNotesDisplay().bracketsOnmouseover) {
+            isOCMouseover = true;
             activateMouseOver();
+        } else {
+            isOCMouseover = false;
+            disableMouseOver();
         }
     }
 
@@ -149,15 +150,13 @@ public class MatchingBlockManager {
      * The contents between the matchings is highlighted.
      **/
     public void setPainterForKeywords() {
-        Parameters param = ConfigSciNotesManager.getDefaultForMatcher("KeywordsHighlighter");
-        if (param.inside) {
-            boolean b = param.type == ScilabKeywordsPainter.FILLED;
-            setPainterForKeywords(b, param.strict, param.included, param.color);
-        } else {
-            setPainterForKeywords(param.type, param.color);
-        }
-        if (param.onmouseover) {
+        setPainterForKeywords(SciNotesOptions.getSciNotesDisplay().keywordsHighlightment == ScilabKeywordsPainter.FILLED, true, false, SciNotesOptions.getSciNotesDisplay().keywordsColor);
+        if (SciNotesOptions.getSciNotesDisplay().keywordsOnmouseover) {
+            isKWMouseover = true;
             activateMouseOver();
+        } else {
+            isKWMouseover = false;
+            disableMouseOver();
         }
     }
 
@@ -165,8 +164,18 @@ public class MatchingBlockManager {
      * Set the defaults from scinotesConfiguration.xml
      */
     public void setDefaults() {
-        setPainterForKeywords();
-        setPainterForOpenClose();
+        if (SciNotesOptions.getSciNotesDisplay().highlightKeywords) {
+            setPainterForKeywords();
+        }
+        if (SciNotesOptions.getSciNotesDisplay().highlightBrackets) {
+            setPainterForOpenClose();
+        }
+    }
+
+    public void configurationChanged(SciNotesConfiguration.Conf conf) {
+        if (conf.display) {
+            setDefaults();
+        }
     }
 
     /**
@@ -180,6 +189,16 @@ public class MatchingBlockManager {
     }
 
     /**
+     * Activate this MatchingBlockManager to listen to the KeywordEvent generate by a MouseOver.
+     */
+    public void disableMouseOver() {
+        if (mouseover != null && !isOCMouseover && !isKWMouseover) {
+            pane.removeKeywordListener(mouseover);
+            mouseover = null;
+        }
+    }
+
+    /**
      * Desactivate this MatchingBlockManager to listen to the KeywordEvent generate by a MouseOver.
      */
     public void desactivateMouseOver() {
@@ -208,7 +227,7 @@ public class MatchingBlockManager {
      * @param tok the type of the token at the position pos in the document
      * @param pos the positon in the doc
      */
-    public synchronized void searchMatchingBlock(int tok, int pos) {
+    public synchronized void searchMatchingBlock(boolean isMouse, int tok, int pos) {
         MatchingBlockScanner.MatchingPositions mpos = null;
         if (ScilabLexerConstants.isMatchable(tok)) {
             mpos = scanner.getMatchingBlock(pos, lr);
@@ -221,9 +240,9 @@ public class MatchingBlockManager {
                     highlighter.removeHighlight(second);
                 }
             }
-            if (mpos != null && ScilabLexerConstants.isOpenClose(tok)) {
+            if (mpos != null && ScilabLexerConstants.isOpenClose(tok) && ocPainter != null && (!isMouse || isOCMouseover)) {
                 createHighlights(mpos, insideOc, ocIncluded, ocPainter);
-            } else if (mpos != null) {
+            } else if (mpos != null && kwPainter != null && (!isMouse || isKWMouseover)) {
                 createHighlights(mpos, insideKw, kwIncluded, kwPainter);
             }
         }
@@ -361,20 +380,20 @@ public class MatchingBlockManager {
                                 Shape bounds, JTextComponent c, View view) {
             try {
                 Rectangle r = (Rectangle) view.modelToView(offs0, Position.Bias.Forward,
-                                                           offs1, Position.Bias.Backward, bounds);
+                              offs1, Position.Bias.Backward, bounds);
                 g.setColor(color);
 
                 switch (type) {
-                case UNDERLINED :
-                    g.drawLine(r.x, r.y + r.height - 1, r.x + r.width - 1, r.y + r.height - 1);
-                    return r;
-                case FRAMED :
-                    g.drawRect(r.x, r.y, r.width - 1, r.height - 1);
-                    return r;
-                case FILLED :
-                default :
-                    g.fillRect(r.x, r.y, r.width, r.height);
-                    return r;
+                    case UNDERLINED :
+                        g.drawLine(r.x, r.y + r.height - 1, r.x + r.width - 1, r.y + r.height - 1);
+                        return r;
+                    case FRAMED :
+                        g.drawRect(r.x, r.y, r.width - 1, r.height - 1);
+                        return r;
+                    case FILLED :
+                    default :
+                        g.fillRect(r.x, r.y, r.width, r.height);
+                        return r;
                 }
             } catch (BadLocationException e) {
                 return null;
@@ -490,9 +509,9 @@ public class MatchingBlockManager {
          */
         public void caughtKeyword(KeywordEvent e) {
             if (lr) {
-                searchMatchingBlock(e.getType(), e.getStart());
+                searchMatchingBlock(true, e.getType(), e.getStart());
             } else {
-                searchMatchingBlock(e.getType(), e.getStart() + e.getLength());
+                searchMatchingBlock(true, e.getType(), e.getStart() + e.getLength());
             }
         }
     }
index 8abb828..d0044af 100644 (file)
@@ -33,6 +33,7 @@ import java.util.UUID;
 import java.util.logging.Logger;
 
 import javax.swing.BorderFactory;
+import javax.swing.JComponent;
 import javax.swing.JFileChooser;
 import javax.swing.JFrame;
 import javax.swing.JOptionPane;
@@ -46,7 +47,12 @@ import javax.swing.text.EditorKit;
 import javax.swing.text.View;
 import javax.swing.undo.UndoManager;
 
+import org.w3c.dom.Document;
+
 import org.flexdock.docking.event.DockingEvent;
+import org.scilab.modules.commons.xml.ScilabXMLUtilities;
+import org.scilab.modules.commons.xml.XConfiguration;
+import static org.scilab.modules.commons.xml.XConfiguration.XConfAttribute;
 import org.scilab.modules.core.Scilab;
 import org.scilab.modules.gui.bridge.filechooser.SwingScilabFileChooser;
 import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
@@ -107,6 +113,9 @@ public class SciNotes extends SwingScilabTab {
 
     private static final long serialVersionUID = -6410183357490518676L;
 
+    private static final String XPATH_SCINOTES_KEY = "//general/shortcuts/body/actions/action-folder[@name='Scinotes']/action";
+    private static final String XPATH_SCINOTES_ACTION = "/map/scinotes/entry";
+
     private static final String SCINOTES = "SciNotes";
     private static final String SCI_EXTENSION = ".sci";
     private static final String SCE_EXTENSION = ".sce";
@@ -127,6 +136,9 @@ public class SciNotes extends SwingScilabTab {
 
     private static final String DEFAULTACTIONPATH = "org.scilab.modules.scinotes.actions";
 
+    private static final Map<String, String> actionToName;
+    private static Map<String, KeyStroke> actionKeys;
+
     private static List<SciNotes> scinotesList = new ArrayList<SciNotes>();
     private static SciNotes editor;
 
@@ -159,6 +171,10 @@ public class SciNotes extends SwingScilabTab {
                 updateSciNotes();
             }
         });
+
+        Document doc = ScilabXMLUtilities.readDocument(System.getenv("SCI") + "/modules/console/etc/Actions-Configuration.xml");
+        actionToName = XConfiguration.get(doc, "name", String.class, "action", String.class, XPATH_SCINOTES_ACTION);
+        XConfiguration.addXConfigurationListener(new SciNotesConfiguration());
     }
 
     /**
@@ -203,6 +219,25 @@ public class SciNotes extends SwingScilabTab {
         this(UUID.randomUUID().toString());
     }
 
+    public static void configurationChanged(SciNotesConfiguration.Conf conf) {
+        setWhereamiLineNumbering();
+        setAutoIndent();
+        updatePanes(conf);
+    }
+
+    public static Map<String, KeyStroke> getActionKeys() {
+        if (actionKeys == null) {
+            Document doc = XConfiguration.getXConfigurationDocument();
+            actionKeys = XConfiguration.get(doc, "name", String.class, "key", KeyStroke.class, XPATH_SCINOTES_KEY);
+        }
+
+        return actionKeys;
+    }
+
+    public static Map<String, String> getActionName() {
+        return actionToName;
+    }
+
     /**
      * Get an opened editor from its uuid
      *
@@ -969,10 +1004,10 @@ public class SciNotes extends SwingScilabTab {
         // process and return true
         if (!textPaneAt.checkExternalModif() && !((ScilabDocument) textPaneAt.getDocument()).isContentModified() && (textPaneAt.getName() != null)) {
             /*
-                                                                                                                                                           * Bug
-                                                                                                                                                           * 5103
-                                                                                                                                                           * fix
-                                                                                                                                                           */
+             * Bug
+             * 5103
+             * fix
+             */
             return true;
         }
 
@@ -1336,16 +1371,17 @@ public class SciNotes extends SwingScilabTab {
      */
     public void initPane(ScilabEditorPane pane, boolean plain) {
         setHighlight(pane);
-       ScilabEditorKit kit = new ScilabEditorKit(plain);
+        ScilabEditorKit kit = new ScilabEditorKit(plain);
         pane.setEditorKit(kit);
 
         // Panel of line number for the text pane
-        pane.getXln().setWhereamiLineNumbering(ConfigSciNotesManager.getLineNumberingState());
+        pane.getXln().setWhereamiLineNumbering(SciNotesOptions.getSciNotesDisplay().showLineNumbers, SciNotesOptions.getSciNotesDisplay().whereami);
         activateHelpOnTyping(pane);
 
         pane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
         pane.setFont(kit.getStylePreferences().tokenFonts[0]);
 
+        // TODO rajouter ca ds les prefs
         pane.setBackground(ConfigSciNotesManager.getSciNotesBackgroundColor());
         pane.setCaretColor(ConfigSciNotesManager.getSciNotesForegroundColor());
 
@@ -1737,14 +1773,14 @@ public class SciNotes extends SwingScilabTab {
      * @param state
      *            int
      */
-    public static void setWhereamiLineNumbering(int state) {
+    public static void setWhereamiLineNumbering() {
         for (SciNotes ed : scinotesList) {
             int n = ed.getTabPane().getTabCount();
             for (int i = 0; i < n; i++) {
                 ScilabEditorPane sep = ed.getTextPane(i);
-                sep.getXln().setWhereamiLineNumbering(state);
+                sep.getXln().setWhereamiLineNumbering(SciNotesOptions.getSciNotesDisplay().showLineNumbers, SciNotesOptions.getSciNotesDisplay().whereami);
                 if (sep.getOtherPaneInSplit() != null) {
-                    sep.getOtherPaneInSplit().getXln().setWhereamiLineNumbering(state);
+                    sep.getOtherPaneInSplit().getXln().setWhereamiLineNumbering(SciNotesOptions.getSciNotesDisplay().showLineNumbers, SciNotesOptions.getSciNotesDisplay().whereami);
                 }
             }
             ed.repaint();
@@ -1757,14 +1793,14 @@ public class SciNotes extends SwingScilabTab {
      * @param b
      *            true to activate auto-indent mode
      */
-    public static void setAutoIndent(boolean b) {
+    public static void setAutoIndent() {
         for (SciNotes ed : scinotesList) {
             int n = ed.getTabPane().getTabCount();
             for (int i = 0; i < n; i++) {
                 ScilabEditorPane sep = ed.getTextPane(i);
-                ((ScilabDocument) sep.getDocument()).setAutoIndent(b);
+                ((ScilabDocument) sep.getDocument()).setAutoIndent(SciNotesOptions.getSciNotesDisplay().automaticIndent);
                 if (sep.getOtherPaneInSplit() != null) {
-                    ((ScilabDocument) sep.getOtherPaneInSplit().getDocument()).setAutoIndent(b);
+                    ((ScilabDocument) sep.getOtherPaneInSplit().getDocument()).setAutoIndent(SciNotesOptions.getSciNotesDisplay().automaticIndent);
                 }
             }
         }
@@ -1806,7 +1842,7 @@ public class SciNotes extends SwingScilabTab {
                     sep.copyProps(pane);
                     pane.setDocument(sep.getDocument());
                     pane.setCaretPosition(sep.getCaretPosition());
-                    pane.getXln().setWhereamiLineNumbering(ConfigSciNotesManager.getLineNumberingState());
+                    pane.getXln().setWhereamiLineNumbering(SciNotesOptions.getSciNotesDisplay().showLineNumbers, SciNotesOptions.getSciNotesDisplay().whereami);
                     ed.tabPane.setComponentAt(i, pane.getEditorComponent());
                     ed.activateHelpOnTyping(pane);
                     ed.initInputMap(pane);
@@ -1820,6 +1856,11 @@ public class SciNotes extends SwingScilabTab {
     }
 
     /**
+         * Set a line numbering compatible with the whereami function
+         * @param state 0 for nothing, 1 for normal and 2 for whereami
+         */
+
+    /**
      * Enable the highlighted line in this editor
      *
      * @param b
@@ -1896,6 +1937,26 @@ public class SciNotes extends SwingScilabTab {
      * @param c
      *            Color
      */
+    public static void updatePanes(SciNotesConfiguration.Conf conf) {
+        for (SciNotes ed : scinotesList) {
+            int n = ed.getTabPane().getTabCount();
+            for (int i = 0; i < n; i++) {
+                ScilabEditorPane sep = ed.getTextPane(i);
+                sep.configurationChanged(conf);
+                if (sep.getOtherPaneInSplit() != null) {
+                    sep.getOtherPaneInSplit().configurationChanged(conf);
+                }
+                sep.repaint();
+            }
+        }
+    }
+
+    /**
+     * Set the color of the highlighted line in this editor
+     *
+     * @param c
+     *            Color
+     */
     public static void setHighlightedLineColor(Color c) {
         for (SciNotes ed : scinotesList) {
             int n = ed.getTabPane().getTabCount();
@@ -2262,39 +2323,48 @@ public class SciNotes extends SwingScilabTab {
      *            the SciNotes editor
      */
     private static void setKeyStrokeAction(ScilabEditorPane sep, SciNotes ed) {
-        Map<String, KeyStroke> map = new HashMap<String, KeyStroke>();
-        ConfigSciNotesManager.addMapActionNameKeys(map);
+        if (ed.getTextPane(0) != sep) {
+            ScilabEditorPane s = ed.getTextPane(0);
+            sep.setInputMap(JComponent.WHEN_FOCUSED, s.getInputMap());
+            return;
+        }
+
+        Map<String, KeyStroke> map = getActionKeys();
 
         ClassLoader loader = ClassLoader.getSystemClassLoader();
         Iterator<String> iter = map.keySet().iterator();
         while (iter.hasNext()) {
-            String action = iter.next();
-            if (!action.equals("SciNotesCompletionAction")) {
-                String className;
-                if (action.lastIndexOf(DOT) != -1) {
-                    className = action;
+            String actionName = iter.next();
+            KeyStroke key = map.get(actionName);
+            String action = actionToName.get(actionName);
+            if (key != null) {
+                if (!action.equals("SciNotesCompletionAction")) {
+                    String className;
+                    if (action.lastIndexOf(DOT) != -1) {
+                        className = action;
+                    } else {
+                        className = DEFAULTACTIONPATH + DOT + action;
+                    }
+                    try {
+                        Class clazz = loader.loadClass(className);
+                        Constructor constructor = clazz.getConstructor(new Class[] { String.class, SciNotes.class });
+                        Object act = constructor.newInstance(new Object[] { "", ed });
+                        sep.getInputMap().put(key, act);
+                    } catch (ClassNotFoundException e) {
+                        System.err.println("No action: " + className);
+                    } catch (InstantiationException e) {
+                        System.err.println("Problem to instantiate in action: " + className);
+                    } catch (NoSuchMethodException e) {
+                        System.err.println("No valid constructor in action: " + className);
+                    } catch (IllegalAccessException e) {
+                        System.err.println("The constructor must be public: " + className);
+                    } catch (InvocationTargetException e) {
+                        System.err.println("The constructor in " + className + " threw an exception :");
+                        e.printStackTrace();
+                    }
                 } else {
-                    className = DEFAULTACTIONPATH + DOT + action;
+                    sep.getInputMap().put(key, new SciNotesCompletionAction(sep, ed));
                 }
-                try {
-                    Class clazz = loader.loadClass(className);
-                    Constructor constructor = clazz.getConstructor(new Class[] { String.class, SciNotes.class });
-                    Object act = constructor.newInstance(new Object[] { "", ed });
-                    sep.getInputMap().put(map.get(action), act);
-                } catch (ClassNotFoundException e) {
-                    System.err.println("No action: " + className);
-                } catch (InstantiationException e) {
-                    System.err.println("Problem to instantiate in action: " + className);
-                } catch (NoSuchMethodException e) {
-                    System.err.println("No valid constructor in action: " + className);
-                } catch (IllegalAccessException e) {
-                    System.err.println("The constructor must be public: " + className);
-                } catch (InvocationTargetException e) {
-                    System.err.println("The constructor in " + className + " threw an exception :");
-                    e.printStackTrace();
-                }
-            } else {
-                sep.getInputMap().put(map.get(action), new SciNotesCompletionAction(sep, ed));
             }
         }
     }
diff --git a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesConfiguration.java b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesConfiguration.java
new file mode 100644 (file)
index 0000000..ceb3001
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.scinotes;
+
+import java.util.Set;
+
+import org.scilab.modules.commons.xml.XConfigurationEvent;
+import org.scilab.modules.commons.xml.XConfigurationListener;
+
+public class SciNotesConfiguration implements XConfigurationListener {
+
+    public SciNotesConfiguration() { }
+
+    /**
+     * Prevent the listener that configuration has changed
+     *
+     * @param e the event
+     */
+    public void configurationChanged(XConfigurationEvent e) {
+        Conf conf = new Conf(e.getModifiedPaths());
+        if (conf.changed()) {
+            SciNotesOptions.invalidate(conf);
+            SciNotes.configurationChanged(conf);
+        }
+    }
+
+    public static class Conf {
+
+        public boolean preferences;
+        public boolean display;
+        public boolean autosave;
+        public boolean colors;
+        public boolean systemfont;
+        public boolean font;
+
+        public Conf(Set<String> path) {
+            preferences = path.contains(SciNotesOptions.PREFERENCESPATH);
+            display = path.contains(SciNotesOptions.DISPLAYPATH);
+            autosave = path.contains(SciNotesOptions.AUTOSAVEPATH);
+            colors = path.contains(ScilabContext.COLORSPATH);
+            systemfont = path.contains(ScilabContext.SYSTEMFONTPATH);
+            font = path.contains(ScilabContext.FONTPATH);
+        }
+
+        public boolean changed() {
+            return preferences || display || autosave || colors || systemfont || font;
+        }
+    }
+}
index 538df55..3fc383d 100644 (file)
@@ -73,7 +73,6 @@ public final class SciNotesGUI {
 
     private static final String DEFAULTACTIONPATH = "org.scilab.modules.scinotes.actions";
 
-    private static Map<String, KeyStroke> map = new HashMap<String, KeyStroke>();
     private static Document menuConf;
 
     private static Map<SciNotes, MenuBar> mapMenuBar = new HashMap<SciNotes, MenuBar>();
@@ -81,10 +80,6 @@ public final class SciNotesGUI {
     private static Map<SciNotes, JPopupMenu> mapPopup = new HashMap<SciNotes, JPopupMenu>();
     private static Map<SciNotes, TextBox> mapInfoBar = new HashMap<SciNotes, TextBox>();
 
-    static {
-        ConfigSciNotesManager.addMapActionNameKeys(map);
-    }
-
     /**
      * initialize the window
      * @param mainWindow Windows
@@ -115,13 +110,6 @@ public final class SciNotesGUI {
     }
 
     /**
-     * @return the Map containing the pairs (Action, KeyStroke).
-     */
-    public static Map<String, KeyStroke> getActionKeyMap() {
-        return map;
-    }
-
-    /**
      * @param editor the editor
      * @return the infobar of the editor
      */
@@ -303,14 +291,15 @@ public final class SciNotesGUI {
         ClassLoader loader = ClassLoader.getSystemClassLoader();
         String className = "";
         Method method = null;
+        String actionClass = SciNotes.getActionName().get(action);
         try {
             if (action.lastIndexOf(DOT) != -1)  {
-                className = action;
+                className = actionClass;
             } else {
-                className = DEFAULTACTIONPATH + DOT + action;
+                className = DEFAULTACTIONPATH + DOT + actionClass;
             }
             Class clazz = loader.loadClass(className);
-            method = clazz.getMethod("createMenu", new Class[]{String.class, SciNotes.class, KeyStroke.class});
+            method = clazz.getMethod("createMenu", new Class[] {String.class, SciNotes.class, KeyStroke.class});
         } catch (ClassNotFoundException e) {
             System.err.println("No action: " + className);
         } catch (NoSuchMethodException e) {
@@ -322,14 +311,14 @@ public final class SciNotesGUI {
         }
 
         try {
-            return method.invoke(null, new Object[]{Messages.gettext(label), editor, map.get(action)});
+            return method.invoke(null, new Object[] {Messages.gettext(label), editor, SciNotes.getActionKeys().get(action)});
         } catch (InvocationTargetException e) {
             System.err.println("Warning: problem to create the menu for action: " + className);
             System.err.println("The menu label is: " + Messages.gettext(label));
             System.err.println("English version will be used instead.");
             System.err.println("Please report a bug at: http://bugzilla.scilab.org");
             try {
-                return method.invoke(null, new Object[]{label, editor, map.get(action)});
+                return method.invoke(null, new Object[] {label, editor, SciNotes.getActionKeys().get(action)});
             } catch (InvocationTargetException ex) {
                 System.err.println("Problem to create menu of the action: " + className);
             } catch (IllegalAccessException ex) {
@@ -352,15 +341,16 @@ public final class SciNotesGUI {
     private static Object getButton(String action, String tooltip, String icon, SciNotes editor) {
         ClassLoader loader = ClassLoader.getSystemClassLoader();
         String className = "";
+        String actionClass = SciNotes.getActionName().get(action);
         try {
             if (action.lastIndexOf(DOT) != -1)  {
-                className = action;
+                className = actionClass;
             } else {
-                className = DEFAULTACTIONPATH + DOT + action;
+                className = DEFAULTACTIONPATH + DOT + actionClass;
             }
             Class clazz = loader.loadClass(className);
-            Method method = clazz.getMethod("createButton", new Class[]{String.class, String.class, SciNotes.class});
-            return method.invoke(null, new Object[]{Messages.gettext(tooltip), icon, editor});
+            Method method = clazz.getMethod("createButton", new Class[] {String.class, String.class, SciNotes.class});
+            return method.invoke(null, new Object[] {Messages.gettext(tooltip), icon, editor});
         } catch (ClassNotFoundException e) {
             System.err.println("No action: " + className);
         } catch (NoSuchMethodException e) {
index 31e72b1..5b0bccd 100644 (file)
@@ -118,6 +118,37 @@ public class SciNotesLineNumberPanel extends JPanel implements CaretListener, Do
         this.state = state;
     }
 
+    public static int getState(boolean showLinesNumber, boolean whereami) {
+        if (!showLinesNumber) {
+            return 0;
+        } else if (!whereami) {
+            return 1;
+        } else {
+            return 2;
+        }
+    }
+
+    public static boolean[] getState(int state) {
+        switch (state) {
+            case 0:
+                return new boolean[] { false, false };
+            case 1:
+                return new boolean[] { true, false };
+            case 2:
+                return new boolean[] { true, true };
+            default:
+                return null;
+        }
+    }
+
+    /**
+     * Set a line numbering compatible with the whereami function
+     * @param state 0 for nothing, 1 for normal and 2 for whereami
+     */
+    public void setWhereamiLineNumbering(boolean showLinesNumber, boolean whereami) {
+        setWhereamiLineNumbering(getState(showLinesNumber, whereami));
+    }
+
     /**
      * Get the number of the lines used in the panel
      * @return the lines number depending on whereami mode or none
@@ -329,25 +360,25 @@ public class SciNotesLineNumberPanel extends JPanel implements CaretListener, Do
                 elem = (ScilabDocument.ScilabLeafElement) root.getElement(i);
                 int type = elem.getType();
                 switch (type) {
-                case ScilabDocument.ScilabLeafElement.NOTHING :
-                    lineNumber[i] = current++;
-                    lineLevel[i] = (byte) stk.size();
-                    break;
-                case ScilabDocument.ScilabLeafElement.FUN :
-                    stk.push(new Integer(current));
-                    lineLevel[i] = (byte) stk.size();
-                    current = 2;
-                    lineNumber[i] = 1;
-                    break;
-                case ScilabDocument.ScilabLeafElement.ENDFUN :
-                    lineNumber[i] = current++;
-                    lineLevel[i] = (byte) stk.size();
-                    if (!stk.empty()) {
-                        current = stk.pop().intValue() + lineNumber[i];
-                    }
-                    break;
-                default :
-                    break;
+                    case ScilabDocument.ScilabLeafElement.NOTHING :
+                        lineNumber[i] = current++;
+                        lineLevel[i] = (byte) stk.size();
+                        break;
+                    case ScilabDocument.ScilabLeafElement.FUN :
+                        stk.push(new Integer(current));
+                        lineLevel[i] = (byte) stk.size();
+                        current = 2;
+                        lineNumber[i] = 1;
+                        break;
+                    case ScilabDocument.ScilabLeafElement.ENDFUN :
+                        lineNumber[i] = current++;
+                        lineLevel[i] = (byte) stk.size();
+                        if (!stk.empty()) {
+                            current = stk.pop().intValue() + lineNumber[i];
+                        }
+                        break;
+                    default :
+                        break;
                 }
             }
         }
diff --git a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesOptions.java b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotesOptions.java
new file mode 100644 (file)
index 0000000..34a86e0
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2012 - Scilab Enterprises -Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.scinotes;
+
+import java.awt.Color;
+
+import org.w3c.dom.Document;
+
+import static org.scilab.modules.commons.xml.XConfiguration.XConfAttribute;
+import org.scilab.modules.commons.xml.XConfiguration;
+
+/**
+ * The class ScilabContext provides a context to render a Scilab's document.
+ * @author Calixte DENIZET
+ */
+public class SciNotesOptions {
+
+    public static final String PREFERENCESPATH = "//scinotes/body/scinotes-preferences";
+    public static final String DISPLAYPATH = "//scinotes/display/body/scinotes-display";
+    public static final String AUTOSAVEPATH = "//scinotes/autosave/body/scinotes-autosave";
+
+    private static SciNotesOptions.Preferences prefs;
+    private static SciNotesOptions.Display display;
+    private static SciNotesOptions.Autosave autosave;
+
+    private static Document doc;
+
+    /* scinotes-preferences */
+    @XConfAttribute
+    public static class Preferences {
+
+        public boolean restartOpen;
+        public boolean addLineTermination;
+        public int numberOfRecentlyOpen;
+        public String encoding;
+        public String eol;
+        public boolean externalCmd;
+        public String cmd;
+
+        private Preferences() { }
+
+        @XConfAttribute(tag = "scinotes-preferences", attributes = {"restart-reopen", "add-line-termination", "number-of-recently-open", "encoding", "eol", "scinotes", "cmd", "external-cmd"})
+        private void set(boolean restartOpen, boolean addLineTermination, int numberOfRecentlyOpen, String encoding, String eol, boolean externalCmd, String cmd) {
+            this.restartOpen = restartOpen;
+            this.addLineTermination = addLineTermination;
+            this.numberOfRecentlyOpen = numberOfRecentlyOpen;
+            this.encoding = encoding;
+            this.eol = eol;
+            this.externalCmd = externalCmd;
+            this.cmd = cmd;
+        }
+    }
+
+    /* scinotes-display */
+    @XConfAttribute
+    public static class Display {
+
+        public boolean highlightCurrentLine;
+        public Color currentLineColor;
+        public boolean showLineNumbers;
+        public boolean wrapLines;
+        public boolean keywordsColorization;
+        public boolean highlightBrackets;
+        public Color bracketsColor;
+        public int bracketsHighlightment;
+        public boolean bracketsOnmouseover;
+        public boolean highlightKeywords;
+        public Color keywordsColor;
+        public int keywordsHighlightment;
+        public boolean keywordsOnmouseover;
+        public boolean whereami;
+        public int tabSize;
+        public boolean useSpaces;
+        public int indentSize;
+        public boolean automaticIndent;
+
+        private Display() { }
+
+        @XConfAttribute(tag = "scinotes-display", attributes = {"highlight-current-line", "current-line-color", "show-line-numbers", "wrap-lines", "keywordsColorization", "highlight-brackets", "brackets-color", "brackets-highlightment", "brackets-onmouseover", "highlight-keywords", "keywords-color", "keywords-highlightment", "keywords-onmouseover", "whereami", "tab-size", "use-spaces", "indent-size", "automatic-indent"})
+        private void set(boolean highlightCurrentLine, Color currentLineColor, boolean showLineNumbers, boolean wrapLines, boolean keywordsColorization, boolean highlightBrackets, Color bracketsColor, String bracketsHighlightment, boolean bracketsOnmouseover, boolean highlightKeywords, Color keywordsColor, String keywordsHighlightment, boolean keywordsOnmouseover, boolean whereami, int tabSize, boolean useSpaces, int indentSize, boolean automaticIndent) {
+            this.highlightCurrentLine = highlightCurrentLine;
+            this.currentLineColor = currentLineColor;
+            this.showLineNumbers = showLineNumbers;
+            this.wrapLines = wrapLines;
+            this.keywordsColorization = keywordsColorization;
+            this.highlightBrackets = highlightBrackets;
+            this.bracketsColor = bracketsColor;
+            this.bracketsOnmouseover = bracketsOnmouseover;
+            this.highlightKeywords = highlightKeywords;
+            this.keywordsColor = keywordsColor;
+            this.keywordsOnmouseover = keywordsOnmouseover;
+            this.whereami = whereami;
+            this.tabSize = tabSize;
+            this.useSpaces = useSpaces;
+            this.indentSize = indentSize;
+            this.automaticIndent = automaticIndent;
+
+            if (bracketsHighlightment.equalsIgnoreCase("filled")) {
+                this.bracketsHighlightment = MatchingBlockManager.ScilabKeywordsPainter.FILLED;
+            } else if (bracketsHighlightment.equalsIgnoreCase("framed")) {
+                this.bracketsHighlightment = MatchingBlockManager.ScilabKeywordsPainter.FRAMED;
+            } else {
+                this.bracketsHighlightment = MatchingBlockManager.ScilabKeywordsPainter.UNDERLINED;
+            }
+
+            if (keywordsHighlightment.equalsIgnoreCase("filled")) {
+                this.keywordsHighlightment = MatchingBlockManager.ScilabKeywordsPainter.FILLED;
+            } else if (keywordsHighlightment.equalsIgnoreCase("framed")) {
+                this.keywordsHighlightment = MatchingBlockManager.ScilabKeywordsPainter.FRAMED;
+            } else {
+                this.keywordsHighlightment = MatchingBlockManager.ScilabKeywordsPainter.UNDERLINED;
+            }
+        }
+    }
+
+    /* scinotes-autosave */
+    @XConfAttribute
+    public static class Autosave {
+
+        public boolean autoSave;
+        public int saveEvery;
+        public boolean automaticDelete;
+        public String appendWith;
+        public String replaceWith;
+        public boolean sourceFlag;
+        public String singleDirectory;
+
+        private Autosave() { }
+
+        @XConfAttribute(tag = "scinotes-autosave", attributes = {"enable", "save-every", "automatic-delete", "append-with", "replace-with", "source-flag", "single-directory"})
+        private void set(boolean autoSave, int saveEvery, boolean automaticDelete, String appendWith, String replaceWith, boolean sourceFlag, String singleDirectory) {
+            this.autoSave = autoSave;
+            this.saveEvery = saveEvery;
+            this.automaticDelete = automaticDelete;
+            this.appendWith = appendWith;
+            this.replaceWith = replaceWith;
+            this.sourceFlag = sourceFlag;
+            this.singleDirectory = singleDirectory;
+        }
+    }
+
+    public static void invalidate(SciNotesConfiguration.Conf conf) {
+        if (conf.preferences) {
+            prefs = null;
+            doc = null;
+        } else if (conf.display) {
+            display = null;
+            doc = null;
+        } else if (conf.autosave) {
+            autosave = null;
+            doc = null;
+        }
+    }
+
+    public static final SciNotesOptions.Preferences getSciNotesPreferences() {
+        if (prefs == null) {
+            if (doc == null) {
+                doc = XConfiguration.getXConfigurationDocument();
+            }
+            prefs = XConfiguration.get(SciNotesOptions.Preferences.class, doc, PREFERENCESPATH)[0];
+        }
+
+        return prefs;
+    }
+
+    public static final SciNotesOptions.Display getSciNotesDisplay() {
+        if (display == null) {
+            if (doc == null) {
+                doc = XConfiguration.getXConfigurationDocument();
+            }
+            display = XConfiguration.get(SciNotesOptions.Display.class, doc, DISPLAYPATH)[0];
+        }
+
+        return display;
+    }
+
+    public static final SciNotesOptions.Autosave getSciNotesAutosave() {
+        if (autosave == null) {
+            if (doc == null) {
+                doc = XConfiguration.getXConfigurationDocument();
+            }
+            autosave = XConfiguration.get(SciNotesOptions.Autosave.class, doc, AUTOSAVEPATH)[0];
+        }
+
+        return autosave;
+    }
+}
index 48c9055..175575b 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2010 - Calixte DENIZET
+ * Copyright (C) 2011 - Scilab Enterprises -Calixte DENIZET
  *
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
 
 package org.scilab.modules.scinotes;
 
-import java.util.Map;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
 import java.awt.Color;
 import java.awt.Font;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import javax.swing.text.ViewFactory;
 import javax.swing.text.View;
@@ -25,6 +27,7 @@ import javax.swing.text.Element;
 
 import org.w3c.dom.Document;
 
+import static org.scilab.modules.commons.xml.XConfiguration.XConfAttribute;
 
 import org.scilab.modules.commons.xml.XConfiguration;
 import org.scilab.modules.gui.utils.ScilabFontUtils;
@@ -35,6 +38,10 @@ import org.scilab.modules.gui.utils.ScilabFontUtils;
  */
 public class ScilabContext implements ViewFactory {
 
+    public static final String COLORSPATH = "//colors/body/syntax-highlighting-colors/item";
+    public static final String SYSTEMFONTPATH = "//fonts/body/fonts";
+    public static final String FONTPATH = "//fonts/body/fonts/item";
+
     /**
      * Contains the colors of the different tokens
      */
@@ -50,6 +57,12 @@ public class ScilabContext implements ViewFactory {
      */
     public int[] tokenAttrib;
 
+    private Font baseFont;
+    private boolean isDesktop;
+    private boolean compatible;
+    private FontInfo[] scinotesInfos;
+    private FontInfo[] desktopInfos;
+
     private View view;
     private boolean plain;
     private List<Integer> typeToDefault = new ArrayList<Integer>();
@@ -71,29 +84,61 @@ public class ScilabContext implements ViewFactory {
         this.plain = plain;
     }
 
+    public void configurationChanged(SciNotesConfiguration.Conf conf) {
+        boolean modified = false;
+        FontInfo[] scinotes = null;
+        FontInfo[] desktop = null;
+        Document doc = null;
+        if (conf.colors) {
+            genAll();
+            modified = true;
+        }
+
+        if (!modified && conf.font) {
+            doc = XConfiguration.getXConfigurationDocument();
+            scinotes = XConfiguration.get(FontInfo.class, doc, FONTPATH + "[@name='Scinotes']");
+            if (!scinotes[0].equals(scinotesInfos)) {
+                genAll();
+                modified = true;
+            }
+        }
+
+        if (!modified && conf.systemfont) {
+            doc = XConfiguration.getXConfigurationDocument();
+            desktop = XConfiguration.get(FontInfo.class, doc, SYSTEMFONTPATH);
+            genAll();
+        }
+    }
+
     public void genAll() {
         tokenAttrib = new int[ScilabLexerConstants.NUMBEROFTOKENS];
         tokenColors = new Color[ScilabLexerConstants.NUMBEROFTOKENS];
         tokenFonts = new Font[ScilabLexerConstants.NUMBEROFTOKENS];
 
         Document doc = XConfiguration.getXConfigurationDocument();
-        FontInfo[] desktop = XConfiguration.get(FontInfo.class, doc, "//fonts/body/fonts");
-        FontInfo[] scinotes = XConfiguration.get(FontInfo.class, doc, "//fonts/body/fonts/item[@name='Scinotes']");
+        desktopInfos = XConfiguration.get(FontInfo.class, doc, SYSTEMFONTPATH);
+        scinotesInfos = XConfiguration.get(FontInfo.class, doc, FONTPATH + "[@name='Scinotes']");
         Font font;
-        if (scinotes[0].isDesktop()) {
-            font = desktop[0].getFont();
+        if (scinotesInfos[0].isDesktop()) {
+            font = desktopInfos[0].getFont();
+            isDesktop = true;
         } else {
-            font = scinotes[0].getFont();
+            font = scinotesInfos[0].getFont();
+            isDesktop = false;
+        }
+
+        if (font != baseFont) {
+            compatible = ScilabFontUtils.isAllStylesSameWidths(font);
+            baseFont = font;
         }
-        boolean compatible = ScilabFontUtils.isAllStylesSameWidths(font);
 
-        FontDecoration[] decorations = XConfiguration.get(FontDecoration.class, doc, "//colors/body/syntax-highlighting-colors/item");
+        FontDecoration[] decorations = XConfiguration.get(FontDecoration.class, doc, COLORSPATH);
         doc = null;
 
         for (FontDecoration deco : decorations) {
             tokenAttrib[deco.getType()] = deco.getValue();
             tokenColors[deco.getType()] = deco.getColor();
-            tokenFonts[deco.getType()] = compatible ? font.deriveFont(deco.getFontFace()) : font;
+            tokenFonts[deco.getType()] = compatible ? baseFont.deriveFont(deco.getFontFace()) : baseFont;
         }
 
         // Default color and special case
@@ -182,19 +227,19 @@ public class ScilabContext implements ViewFactory {
         Font font = tokenFonts[ScilabLexerConstants.TOKENS.get(name)];
         int style = font.getStyle();
         switch (type) {
-        case -2 :
-            font = font.deriveFont(style & ~Font.ITALIC);
-            break;
-        case -1 :
-            font = font.deriveFont(style & ~Font.BOLD);
-            break;
-        case 1 :
-            font = font.deriveFont(style | Font.BOLD);
-            break;
-        case 2 :
-            font = font.deriveFont(style | Font.ITALIC);
-            break;
-        default :
+            case -2 :
+                font = font.deriveFont(style & ~Font.ITALIC);
+                break;
+            case -1 :
+                font = font.deriveFont(style & ~Font.BOLD);
+                break;
+            case 1 :
+                font = font.deriveFont(style | Font.BOLD);
+                break;
+            case 2 :
+                font = font.deriveFont(style | Font.ITALIC);
+                break;
+            default :
         }
 
         tokenFonts[ScilabLexerConstants.TOKENS.get(name)] = font;
@@ -233,6 +278,7 @@ public class ScilabContext implements ViewFactory {
     /**
      * Inner class to retrieve configuration elements from configuration file
      */
+    @XConfAttribute
     private static class FontInfo {
 
         private String fontname;
@@ -241,15 +287,10 @@ public class ScilabContext implements ViewFactory {
 
         public FontInfo() { }
 
-        public void setFontName(String fontname) {
+        @XConfAttribute(attributes = {"font-name", "font-size", "desktop"})
+        public void set(String fontname, int fontsize, boolean desktop) {
             this.fontname = fontname;
-        }
-
-        public void setFontSize(int fontsize) {
             this.fontsize = fontsize;
-        }
-
-        public void setDesktop(boolean desktop) {
             this.desktop = desktop;
         }
 
@@ -260,11 +301,21 @@ public class ScilabContext implements ViewFactory {
         public Font getFont() {
             return new Font(fontname, Font.PLAIN, fontsize);
         }
+
+        public boolean equals(Object o) {
+            if (o instanceof FontInfo) {
+                FontInfo f = (FontInfo) o;
+                return fontname.equals(f.fontname) && fontsize == f.fontsize && desktop == f.desktop;
+            }
+
+            return false;
+        }
     }
 
     /**
      * Inner class to retrieve configuration elements from configuration file
      */
+    @XConfAttribute
     private static class FontDecoration {
 
         private boolean underline;
@@ -276,28 +327,14 @@ public class ScilabContext implements ViewFactory {
 
         public FontDecoration() { }
 
-        public void setUnderline(boolean underline) {
+        @XConfAttribute(attributes = {"underline", "strike-through", "name", "italic", "color", "bold"})
+        public void set(boolean underline, boolean strikeThrough, String name, boolean italic, Color color, boolean bold) {
             this.underline = underline;
-        }
-
-        public void setStrikeThrough(boolean strikeThrough) {
             this.strikeThrough = strikeThrough;
-        }
-
-        public void setName(String name) {
-            type = ScilabLexerConstants.TOKENS.get(name);
-        }
-
-        public void setColor(Color color) {
+            this.type = ScilabLexerConstants.TOKENS.get(name);
             this.color = color;
-        }
-
-        public void setBold(boolean bold) {
-            this.bold = bold;
-        }
-
-        public void setItalic(boolean italic) {
             this.italic = italic;
+            this.bold = bold;
         }
 
         public int getFontFace() {
@@ -332,5 +369,14 @@ public class ScilabContext implements ViewFactory {
         public int getType() {
             return type;
         }
+
+        public boolean equals(Object o) {
+            if (o instanceof FontDecoration) {
+                FontDecoration f = (FontDecoration) o;
+                return underline == f.underline && strikeThrough == f.strikeThrough && bold == f.bold && italic == f.italic && color.equals(f.color) && type == f.type;
+            }
+
+            return false;
+        }
     }
 }
index 3bcdc71..793ad30 100644 (file)
@@ -42,6 +42,7 @@ import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 import javax.swing.event.CaretEvent;
 import javax.swing.event.CaretListener;
+import javax.swing.event.EventListenerList;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Caret;
 import javax.swing.text.DefaultHighlighter;
@@ -66,9 +67,9 @@ import org.scilab.modules.scinotes.utils.SciNotesMessages;
  *
  */
 public class ScilabEditorPane extends JEditorPane implements Highlighter.HighlightPainter,
-                                                  CaretListener, MouseListener,
-                                                  MouseMotionListener, Cloneable,
-                                                  KeyListener {
+    CaretListener, MouseListener,
+    MouseMotionListener, Cloneable,
+    KeyListener {
 
     private static final long serialVersionUID = 4322071415211939097L;
 
@@ -83,7 +84,8 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
     private Color highlightContourColor;
     private boolean highlightEnable;
     private Object highlightCL;
-    private boolean matchingEnable;
+    private boolean matchingKeywordsEnable;
+    private boolean matchingOpenersEnable;
     private boolean overwriteMode;
     private ScilabLexer lexer;
     private SciNotes editor;
@@ -123,7 +125,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
     private boolean hasBeenSaved;
     private boolean saveHighlightEnable;
 
-    private List<KeywordListener> kwListeners = new ArrayList<KeywordListener>();
+    private EventListenerList kwListeners = new EventListenerList();
     private List<Object> highlightedWords = new ArrayList<Object>();
     private List<Integer> highlightedWordsBegin = new ArrayList<Integer>();
 
@@ -150,35 +152,36 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         addCaretListener(this);
         addMouseMotionListener(this);
         addMouseListener(this);
-        enableMatchingKeywords(true);
+        enableMatchingKeywords(SciNotesOptions.getSciNotesDisplay().highlightKeywords);
+        enableMatchingOpeners(SciNotesOptions.getSciNotesDisplay().highlightBrackets);
         setFocusable(true);
         addFocusListener(new FocusListener() {
-                public void focusGained(FocusEvent e) {
-                    updateInfosWhenFocused();
-                    if (ScilabEditorPane.this.editor != null) {
-                        NavigatorWindow nav = ScilabEditorPane.this.editor.getNavigator();
-                        if (nav != null) {
-                            nav.update((ScilabDocument) getDocument());
-                        }
+            public void focusGained(FocusEvent e) {
+                updateInfosWhenFocused();
+                if (ScilabEditorPane.this.editor != null) {
+                    NavigatorWindow nav = ScilabEditorPane.this.editor.getNavigator();
+                    if (nav != null) {
+                        nav.update((ScilabDocument) getDocument());
                     }
                 }
+            }
 
-                public void focusLost(FocusEvent e) {
-                    ((ScilabDocument) getDocument()).setFocused(false);
-                }
-            });
+            public void focusLost(FocusEvent e) {
+                ((ScilabDocument) getDocument()).setFocused(false);
+            }
+        });
 
         addKeywordListener(new KeywordAdaptater.MouseOverAdaptater() {
-                public void caughtKeyword(KeywordEvent e) {
-                    if (ScilabLexerConstants.isClickable(e.getType())) {
-                        if (ctrlHit) {
-                            setCursor(HANDCURSOR);
-                            hand = true;
-                            try {
-                                String url = ((ScilabDocument) getDocument()).getText(e.getStart(), e.getLength());
-                                if (ScilabLexerConstants.isClickable(e.getType())) {
-                                    String text;
-                                    switch (e.getType()) {
+            public void caughtKeyword(KeywordEvent e) {
+                if (ScilabLexerConstants.isClickable(e.getType())) {
+                    if (ctrlHit) {
+                        setCursor(HANDCURSOR);
+                        hand = true;
+                        try {
+                            String url = ((ScilabDocument) getDocument()).getText(e.getStart(), e.getLength());
+                            if (ScilabLexerConstants.isClickable(e.getType())) {
+                                String text;
+                                switch (e.getType()) {
                                     case ScilabLexerConstants.URL :
                                         text = SciNotesMessages.OPENURL;
                                         break;
@@ -193,68 +196,101 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
                                         break;
                                     default :
                                         text = null;
-                                    }
+                                }
 
-                                    if (text != null && ScilabEditorPane.this.editor != null) {
-                                        ScilabEditorPane.this.editor.getInfoBar().setText(text + url);
-                                        infoBarChanged = true;
-                                    }
+                                if (text != null && ScilabEditorPane.this.editor != null) {
+                                    ScilabEditorPane.this.editor.getInfoBar().setText(text + url);
+                                    infoBarChanged = true;
                                 }
-                            } catch (BadLocationException ex) { }
-                        } else if (ScilabEditorPane.this.editor != null) {
-                            ScilabEditorPane.this.editor.getInfoBar().setText(SciNotesMessages.CLICKABLE_URL);
-                            infoBarChanged = true;
-                        }
+                            }
+                        } catch (BadLocationException ex) { }
+                    } else if (ScilabEditorPane.this.editor != null) {
+                        ScilabEditorPane.this.editor.getInfoBar().setText(SciNotesMessages.CLICKABLE_URL);
+                        infoBarChanged = true;
+                    }
+                } else {
+                    if (hand) {
+                        setCursor(TEXTCURSOR);
+                        hand = false;
+                    }
+                    if (infoBarChanged && ScilabEditorPane.this.editor != null) {
+                        ScilabEditorPane.this.editor.getInfoBar().setText(infoBar);
+                        infoBarChanged = false;
+                    }
+                    if (ScilabLexerConstants.isLaTeX(e.getType())) {
+                        try {
+                            int start = e.getStart();
+                            int end = start + e.getLength();
+                            String exp = ((ScilabDocument) getDocument()).getText(start, e.getLength());
+                            int height = edComponent.getScrollPane().getHeight() + edComponent.getScrollPane().getVerticalScrollBar().getValue();
+                            ScilabLaTeXViewer.displayExpression(ScilabEditorPane.this, height, exp, start, end);
+                        } catch (BadLocationException ex) { }
                     } else {
-                        if (hand) {
-                            setCursor(TEXTCURSOR);
-                            hand = false;
-                        }
-                        if (infoBarChanged && ScilabEditorPane.this.editor != null) {
-                            ScilabEditorPane.this.editor.getInfoBar().setText(infoBar);
-                            infoBarChanged = false;
-                        }
-                        if (ScilabLexerConstants.isLaTeX(e.getType())) {
-                            try {
-                                int start = e.getStart();
-                                int end = start + e.getLength();
-                                String exp = ((ScilabDocument) getDocument()).getText(start, e.getLength());
-                                int height = edComponent.getScrollPane().getHeight() + edComponent.getScrollPane().getVerticalScrollBar().getValue();
-                                ScilabLaTeXViewer.displayExpression(ScilabEditorPane.this, height, exp, start, end);
-                            } catch (BadLocationException ex) { }
-                        } else {
-                            ScilabLaTeXViewer.removeLaTeXViewer(ScilabEditorPane.this);
-                        }
+                        ScilabLaTeXViewer.removeLaTeXViewer(ScilabEditorPane.this);
                     }
                 }
-            });
+            }
+        });
 
         addKeywordListener(new KeywordAdaptater.MouseClickedAdaptater() {
-                public void caughtKeyword(KeywordEvent e) {
-                    if (ctrlHit && ScilabLexerConstants.isClickable(e.getType())) {
-                        try {
-                            hand = false;
-                            ctrlHit = false;
-                            infoBarChanged = false;
-                            setCursor(TEXTCURSOR);
-                            if (ScilabEditorPane.this.editor != null) {
-                                ScilabEditorPane.this.editor.getInfoBar().setText(infoBar);
-                            }
-                            String url = ((ScilabDocument) getDocument()).getText(e.getStart(), e.getLength());
-                            if (ScilabLexerConstants.URL == e.getType() || ScilabLexerConstants.MAIL == e.getType()) {
-                                WebBrowser.openUrl(url);
-                            } else if (ScilabLexerConstants.isOpenable(e.getType())) {
-                                OpenSourceFileOnKeywordAction.openSource(ScilabEditorPane.this, url);
-                            }
-                        } catch (BadLocationException ex) { }
-                    }
+            public void caughtKeyword(KeywordEvent e) {
+                if (ctrlHit && ScilabLexerConstants.isClickable(e.getType())) {
+                    try {
+                        hand = false;
+                        ctrlHit = false;
+                        infoBarChanged = false;
+                        setCursor(TEXTCURSOR);
+                        if (ScilabEditorPane.this.editor != null) {
+                            ScilabEditorPane.this.editor.getInfoBar().setText(infoBar);
+                        }
+                        String url = ((ScilabDocument) getDocument()).getText(e.getStart(), e.getLength());
+                        if (ScilabLexerConstants.URL == e.getType() || ScilabLexerConstants.MAIL == e.getType()) {
+                            WebBrowser.openUrl(url);
+                        } else if (ScilabLexerConstants.isOpenable(e.getType())) {
+                            OpenSourceFileOnKeywordAction.openSource(ScilabEditorPane.this, url);
+                        }
+                    } catch (BadLocationException ex) { }
                 }
-            });
+            }
+        });
 
         addKeyListener(this);
         setTransferHandler(new CopyAsHTMLAction.HTMLTransferHandler());
     }
 
+    public void configurationChanged(SciNotesConfiguration.Conf conf) {
+        ((ScilabEditorKit) getEditorKit()).getStylePreferences().configurationChanged(conf);
+
+        if (conf.display) {
+            boolean kw = SciNotesOptions.getSciNotesDisplay().highlightKeywords;
+            boolean op = SciNotesOptions.getSciNotesDisplay().highlightBrackets;
+
+            if ((kw || op) && (!matchingKeywordsEnable && !matchingOpenersEnable)) {
+                matchLR = new MatchingBlockManager((ScilabDocument) getDocument(), this, true, getHighlighter());
+                matchLR.setDefaults();
+                matchRL = new MatchingBlockManager((ScilabDocument) getDocument(), this, false, getHighlighter());
+                matchRL.setDefaults();
+                enableMatchingKeywords(kw);
+                enableMatchingOpeners(op);
+                return;
+            }
+
+            if ((kw || op) && (matchingKeywordsEnable || matchingOpenersEnable)) {
+                matchLR.configurationChanged(conf);
+                matchRL.configurationChanged(conf);
+                return;
+            }
+
+            if ((!kw && !op) && (matchingKeywordsEnable || matchingOpenersEnable)) {
+                matchLR.desactivateMouseOver();
+                matchLR = null;
+                matchRL.desactivateMouseOver();
+                matchRL = null;
+                return;
+            }
+        }
+    }
+
     /**
      * @return the lexer
      */
@@ -333,8 +369,8 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
     public void keyPressed(KeyEvent e) {
         // Workaround for bug 7238
         if (e.getKeyLocation() == KeyEvent.KEY_LOCATION_NUMPAD
-            && e.getKeyCode() == KeyEvent.VK_DELETE
-            && e.getKeyChar() != KeyEvent.VK_DELETE) {
+                && e.getKeyCode() == KeyEvent.VK_DELETE
+                && e.getKeyChar() != KeyEvent.VK_DELETE) {
             e.setKeyCode(KeyEvent.VK_DECIMAL);
             ctrlHit = false;
         } else if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
@@ -437,11 +473,11 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
      */
     public void init() {
         SwingUtilities.invokeLater(new Runnable() {
-                public void run() {
-                    requestFocus();
-                    setCaretPosition(0);
-                }
-            });
+            public void run() {
+                requestFocus();
+                setCaretPosition(0);
+            }
+        });
     }
 
     /**
@@ -542,7 +578,8 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
     public void copyProps(ScilabEditorPane pane) {
         pane.lastModified = lastModified;
         pane.highlightEnable = highlightEnable;
-        pane.matchingEnable = matchingEnable;
+        pane.matchingKeywordsEnable = matchingKeywordsEnable;
+        pane.matchingOpenersEnable = matchingOpenersEnable;
         pane.suppressCom = suppressCom;
         pane.setName(getName());
         pane.setShortName(getShortName());
@@ -610,6 +647,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         com = null;
         trailingWhite = null;
         enableMatchingKeywords(false);
+        enableMatchingOpeners(false);
         matchLR.desactivateMouseOver();
         matchLR = null;
         matchRL.desactivateMouseOver();
@@ -680,28 +718,28 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
      */
     public void scrollTextToPos(final int pos, final boolean setCaret, final boolean centered) {
         SwingUtilities.invokeLater(new Runnable() {
-                public void run() {
-                    try {
-                        if (setCaret) {
-                            setCaretPosition(pos);
+            public void run() {
+                try {
+                    if (setCaret) {
+                        setCaretPosition(pos);
+                    }
+                    JScrollBar scrollbar = edComponent.getScrollPane().getVerticalScrollBar();
+                    Rectangle rect = modelToView(pos);
+                    if (centered) {
+                        int value = scrollbar.getValue();
+                        int h = scrollbar.getHeight();
+                        if (rect.y < value || rect.y > value + h) {
+                            scrollbar.setValue(Math.max(0, rect.y - h / 2));
                         }
-                        JScrollBar scrollbar = edComponent.getScrollPane().getVerticalScrollBar();
-                        Rectangle rect = modelToView(pos);
-                        if (centered) {
-                            int value = scrollbar.getValue();
-                            int h = scrollbar.getHeight();
-                            if (rect.y < value || rect.y > value + h) {
-                                scrollbar.setValue(Math.max(0, rect.y - h / 2));
-                            }
-                        } else {
-                            if (rect.y > scrollbar.getMaximum()) {
-                                scrollbar.setMaximum(rect.y);
-                            }
-                            scrollbar.setValue(rect.y);
+                    } else {
+                        if (rect.y > scrollbar.getMaximum()) {
+                            scrollbar.setMaximum(rect.y);
                         }
-                    } catch (BadLocationException e) { }
-                }
-            });
+                        scrollbar.setValue(rect.y);
+                    }
+                } catch (BadLocationException e) { }
+            }
+        });
     }
 
     /**
@@ -725,20 +763,20 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         if (lineNumber >= 1 && lineNumber <= root.getElementCount()) {
             final int pos = root.getElement(lineNumber - 1).getStartOffset();
             SwingUtilities.invokeLater(new Runnable() {
-                    public void run() {
-                        scrollTextToPos(pos, setCaret, centered);
-                        if (highlight) {
-                            saveHighlightContourColor = highlightContourColor;
-                            highlightContourColor = null;
-                            saveHighlightColor = highlightColor;
-                            highlightColor = Color.YELLOW;
-                            saveHighlightEnable = highlightEnable;
-                            hasBeenSaved = true;
-                            enableHighlightedLine(false);
-                            enableHighlightedLine(true);
-                        }
+                public void run() {
+                    scrollTextToPos(pos, setCaret, centered);
+                    if (highlight) {
+                        saveHighlightContourColor = highlightContourColor;
+                        highlightContourColor = null;
+                        saveHighlightColor = highlightColor;
+                        highlightColor = Color.YELLOW;
+                        saveHighlightEnable = highlightEnable;
+                        hasBeenSaved = true;
+                        enableHighlightedLine(false);
+                        enableHighlightedLine(true);
                     }
-                });
+                }
+            });
         }
     }
 
@@ -882,9 +920,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
      * @param kw a KeywordListener
      */
     public void addKeywordListener(KeywordListener kw) {
-        if (!kwListeners.contains(kw)) {
-            kwListeners.add(kw);
-        }
+        kwListeners.add(KeywordListener.class, kw);
     }
 
     /**
@@ -892,16 +928,14 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
      * @param kw a KeywordListener
      */
     public void removeKeywordListener(KeywordListener kw) {
-        if (kwListeners.contains(kw)) {
-            kwListeners.remove(kw);
-        }
+        kwListeners.remove(KeywordListener.class, kw);
     }
 
     /**
      * @return an array of KeywordListener
      */
     public KeywordListener[] getKeywordListeners() {
-        return kwListeners.toArray(new KeywordListener[0]);
+        return kwListeners.getListeners(KeywordListener.class);
     }
 
     /**
@@ -960,7 +994,15 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
      * @param active true or false
      */
     public void enableMatchingKeywords(boolean active) {
-        matchingEnable = active;
+        matchingKeywordsEnable = active;
+    }
+
+    /**
+     * Enable (active true) or disable (active false) the matching keywords.
+     * @param active true or false
+     */
+    public void enableMatchingOpeners(boolean active) {
+        matchingOpenersEnable = active;
     }
 
     /**
@@ -1001,11 +1043,11 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
 
         int pos = getCaretPosition();
 
-        if (matchingEnable) {
+        if (matchingKeywordsEnable || matchingOpenersEnable) {
             int tok = lexer.getKeyword(pos, false);
-            matchLR.searchMatchingBlock(tok, lexer.start + lexer.yychar());
+            matchLR.searchMatchingBlock(false, tok, lexer.start + lexer.yychar());
             tok = lexer.getKeyword(pos, true);
-            matchRL.searchMatchingBlock(tok, lexer.start + lexer.yychar() + lexer.yylength());
+            matchRL.searchMatchingBlock(false, tok, lexer.start + lexer.yychar() + lexer.yylength());
         }
 
         if (!readonly && !binary && editor != null) {
@@ -1138,11 +1180,16 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
      * @param type of the event : KeywordListener.ONMOUSECLICKED or KeywordListener.ONMOUSEOVER
      */
     protected void preventConcernedKeywordListener(int position, EventObject ev, int type) {
-        int tok = lexer.getKeyword(position, true);
-        KeywordEvent kev = new KeywordEvent(this, ev, tok, lexer.start + lexer.yychar(), lexer.yylength());
-        for (KeywordListener listener : kwListeners) {
-            if (type == listener.getType()) {
-                listener.caughtKeyword(kev);
+        KeywordEvent kev = null;
+        Object[] listeners = kwListeners.getListenerList();
+        for (int i = listeners.length - 2; i >= 0; i -= 2) {
+            if (listeners[i] == KeywordListener.class && type == ((KeywordListener) listeners[i + 1]).getType()) {
+                if (kev == null) {
+                    int tok = lexer.getKeyword(position, true);
+                    kev = new KeywordEvent(this, ev, tok, lexer.start + lexer.yychar(), lexer.yylength());
+                }
+
+                ((KeywordListener) listeners[i + 1]).caughtKeyword(kev);
             }
         }
     }
@@ -1318,17 +1365,17 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
             final Caret caret = new SciNotesCaret(this);
             setCaretColor(getCaretColor());
             SwingUtilities.invokeLater(new Runnable() {
-                    public void run() {
-                        int blinkRate = 500;
-                        Object o = UIManager.get("TextComponent.caretBlinkRate");
-                        if ((o != null) && (o instanceof Integer)) {
-                            Integer rate = (Integer) o;
-                            blinkRate = rate.intValue();
-                        }
-                        caret.setBlinkRate(blinkRate);
-                        caret.setVisible(true);
+                public void run() {
+                    int blinkRate = 500;
+                    Object o = UIManager.get("TextComponent.caretBlinkRate");
+                    if ((o != null) && (o instanceof Integer)) {
+                        Integer rate = (Integer) o;
+                        blinkRate = rate.intValue();
                     }
-                });
+                    caret.setBlinkRate(blinkRate);
+                    caret.setVisible(true);
+                }
+            });
             super.setCaret(caret);
         } else {
             super.setCaret(c);
@@ -1469,10 +1516,14 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         tab.setDefaultTabulation();
         com = new CommentManager(doc);
         trailingWhite = new TrailingWhiteManager(doc);
-        matchLR = new MatchingBlockManager(doc, this, true, getHighlighter());
-        matchLR.setDefaults();
-        matchRL = new MatchingBlockManager(doc, this, false, getHighlighter());
-        matchRL.setDefaults();
+
+        if (matchingKeywordsEnable || matchingOpenersEnable) {
+            matchLR = new MatchingBlockManager(doc, this, true, getHighlighter());
+            matchLR.setDefaults();
+            matchRL = new MatchingBlockManager(doc, this, false, getHighlighter());
+            matchRL.setDefaults();
+        }
+
         lexer = doc.createLexer();
         xln = new SciNotesLineNumberPanel(this);
 
diff --git a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/AutoIndentAction.java b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/AutoIndentAction.java
deleted file mode 100644 (file)
index 82326c1..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2009 - DIGITEO - Bruno JOFRET
- *
- * This file must be used under the terms of the CeCILL.
- * This source file is licensed as described in the file COPYING, which
- * you should have received as part of this distribution.  The terms
- * are also available at
- * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
- *
- */
-
-package org.scilab.modules.scinotes.actions;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.KeyStroke;
-
-import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
-import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
-
-/**
- * AutoIndentAction Class
- * @author Bruno JOFRET
- *
- */
-public final class AutoIndentAction extends DefaultCheckAction  {
-
-    /**
-     * serialVersionUID
-     */
-    private static final long serialVersionUID = -1937347660350539353L;
-
-    /**
-     * Constructor
-     * @param name the name of the action
-     * @param editor SciNotes
-     */
-    public AutoIndentAction(String name, SciNotes editor) {
-        super(name, editor);
-    }
-
-    /**
-     * doAction
-     */
-    public void doAction() {
-        SciNotes.setAutoIndent(this.getState());
-        ConfigSciNotesManager.saveAutoIndent(this.getState());
-    }
-
-    /**
-     * createCheckBoxMenu
-     * @param label label of the menu
-     * @param editor SciNotes
-     * @param key KeyStroke
-     * @return CheckBoxMenuItem
-     */
-    public static CheckBoxMenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
-        final CheckBoxMenuItem autoIndent = createCheckBoxMenu(label, null, new AutoIndentAction(label, editor), key);
-        autoIndent.setChecked(ConfigSciNotesManager.getAutoIndent());
-        ((JCheckBoxMenuItem) autoIndent.getAsSimpleCheckBoxMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
-                public void propertyChange(PropertyChangeEvent e) {
-                    autoIndent.setChecked(ConfigSciNotesManager.getAutoIndent());
-                }
-            });
-
-        return autoIndent;
-    }
-}
index 6bb341c..e602cf0 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2009 - DIGITEO - Bruno JOFRET
  * Copyright (C) 2010 - Calixte DENIZET
  *
  * This file must be used under the terms of the CeCILL.
@@ -24,14 +23,17 @@ import javax.swing.JMenu;
 import javax.swing.JRadioButtonMenuItem;
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.commons.xml.XConfiguration;
 import org.scilab.modules.gui.menu.Menu;
 import org.scilab.modules.gui.menu.ScilabMenu;
 import org.scilab.modules.scinotes.SciNotes;
+import org.scilab.modules.scinotes.SciNotesConfiguration;
+import org.scilab.modules.scinotes.SciNotesOptions;
+import org.scilab.modules.scinotes.SciNotesLineNumberPanel;
 import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
 
 /**
  * LineNumbersAction Class
- * @author Bruno JOFRET
  * @author Calixte DENIZET
  */
 public final class LineNumbersAction extends DefaultAction {
@@ -41,7 +43,8 @@ public final class LineNumbersAction extends DefaultAction {
      */
     private static final long serialVersionUID = -2778300710964013775L;
 
-    private int state;
+    private static int state;
+    private final JRadioButtonMenuItem[] arr = new JRadioButtonMenuItem[3];
 
     /**
      * Construtor
@@ -50,15 +53,36 @@ public final class LineNumbersAction extends DefaultAction {
      */
     public LineNumbersAction(String name, SciNotes editor) {
         super(name, editor);
-        state = ConfigSciNotesManager.getLineNumberingState();
+        init();
     }
 
     /**
      * doAction
      */
-    public void doAction() {
-        SciNotes.setWhereamiLineNumbering(state);
-        ConfigSciNotesManager.saveLineNumberingState(state);
+    public void doAction() { }
+
+    private static int getState() {
+        return SciNotesLineNumberPanel.getState(SciNotesOptions.getSciNotesDisplay().showLineNumbers, SciNotesOptions.getSciNotesDisplay().whereami);
+    }
+
+    private static void setState(int state) {
+        boolean[] states = SciNotesLineNumberPanel.getState(state);
+        SciNotesOptions.getSciNotesDisplay().showLineNumbers = states[0];
+        SciNotesOptions.getSciNotesDisplay().whereami = states[1];
+        XConfiguration.set(XConfiguration.getXConfigurationDocument(), SciNotesOptions.DISPLAYPATH + "/@show-line-numbers", Boolean.toString(states[0]));
+        XConfiguration.set(XConfiguration.getXConfigurationDocument(), SciNotesOptions.DISPLAYPATH + "/@whereami", Boolean.toString(states[1]));
+        SciNotes.setWhereamiLineNumbering();
+    }
+
+    private void init() {
+        ButtonGroup group = new ButtonGroup();
+        JRadioButtonMenuItem radio;
+
+        for (int i = 0; i < 3; i++) {
+            radio = createRadioButtonMenuItem(i);
+            group.add(radio);
+            arr[i] = radio;
+        }
     }
 
     /**
@@ -75,30 +99,24 @@ public final class LineNumbersAction extends DefaultAction {
         String labelNormal = tokens.nextToken();
         String labelWhereami = tokens.nextToken();
 
-        LineNumbersAction ln = new LineNumbersAction(labelLineNumbering, editor);
-        final JRadioButtonMenuItem[] arr = new JRadioButtonMenuItem[3];
-        String[] labels = new String[]{labelOff, labelNormal, labelWhereami};
+        final LineNumbersAction ln = new LineNumbersAction(labelLineNumbering, editor);
+        String[] labels = new String[] {labelOff, labelNormal, labelWhereami};
 
         final Menu menu = ScilabMenu.createMenu();
         menu.setText(labelLineNumbering);
 
-        ButtonGroup group = new ButtonGroup();
-        JRadioButtonMenuItem radio;
+        ln.arr[getState()].setSelected(true);
 
         for (int i = 0; i < 3; i++) {
-            radio = createRadioButtonMenuItem(ln, labels[i], i);
-            group.add(radio);
-            ((JMenu) menu.getAsSimpleMenu()).add(radio);
-            arr[i] = radio;
+            ((JMenu) menu.getAsSimpleMenu()).add(ln.arr[i]);
+            ln.arr[i].setText(labels[i]);
         }
 
-        arr[ln.state].setSelected(true);
-
         ((JMenu) menu.getAsSimpleMenu()).addPropertyChangeListener(new PropertyChangeListener() {
-                public void propertyChange(PropertyChangeEvent e) {
-                    arr[ConfigSciNotesManager.getLineNumberingState()].setSelected(true);
-                }
-            });
+            public void propertyChange(PropertyChangeEvent e) {
+                ln.arr[getState()].setSelected(true);
+            }
+        });
 
         return menu;
     }
@@ -110,14 +128,13 @@ public final class LineNumbersAction extends DefaultAction {
      * @param state the state associated with the menuitem
      * @return JRadioButtonMenuItem
      */
-    private static JRadioButtonMenuItem createRadioButtonMenuItem(final LineNumbersAction ln, String title, final int state) {
-        JRadioButtonMenuItem radio = new JRadioButtonMenuItem(title);
+    private static JRadioButtonMenuItem createRadioButtonMenuItem(final int state) {
+        JRadioButtonMenuItem radio = new JRadioButtonMenuItem();
         radio.addActionListener(new ActionListener() {
-                public void actionPerformed(ActionEvent arg0) {
-                    ln.state = state;
-                    ln.doAction();
-                }
-            });
+            public void actionPerformed(ActionEvent arg0) {
+                LineNumbersAction.setState(state);
+            }
+        });
 
         return radio;
     }
index 360aa25..7f3bac6 100644 (file)
@@ -47,7 +47,9 @@ public class RemoveAnchorAction extends DefaultAction {
         ScilabDocument.ScilabLeafElement line = (ScilabDocument.ScilabLeafElement) root.getElement(root.getElementIndex(sep.getCaretPosition()));
         line.setAnchor(null);
         sep.getXln().repaint();
-        getEditor().getNavigator().update();
+        if (getEditor().getNavigator() != null) {
+            getEditor().getNavigator().update();
+        }
     }
 
     /**
index 34b9e02..0acd67a 100644 (file)
@@ -85,7 +85,7 @@ import org.scilab.modules.scinotes.tabfactory.CodeNavigatorTabFactory;
  * @author Calixte DENIZET
  */
 public final class NavigatorWindow extends SwingScilabTab implements DocumentListener,
-TreeExpansionListener {
+    TreeExpansionListener {
 
     private static final String EMPTY = "";
 
@@ -286,14 +286,14 @@ TreeExpansionListener {
     public void changeToolBar() {
         SwingScilabWindow win = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this);
         if (win != null && win.getDockingPort() != null) {
-           Set<SwingScilabTab> set = (Set<SwingScilabTab>) win.getDockingPort().getDockables();
-           for (SwingScilabTab tab : set) {
-               if (tab == editor) {
-                   addToolBar(editor.getToolBar());
-                   break;
-               }
-           }
-       }
+            Set<SwingScilabTab> set = (Set<SwingScilabTab>) win.getDockingPort().getDockables();
+            for (SwingScilabTab tab : set) {
+                if (tab == editor) {
+                    addToolBar(editor.getToolBar());
+                    break;
+                }
+            }
+        }
     }
 
     /**
@@ -466,37 +466,37 @@ TreeExpansionListener {
         GroupLayout layout = new GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
         layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING)
-                .addGroup(layout.createSequentialGroup()
-                        .addContainerGap()
-                        .addGroup(layout.createParallelGroup(Alignment.LEADING)
-                                .addComponent(scrollPane, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
-                                .addComponent(jSeparator1, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
-                                .addGroup(layout.createSequentialGroup()
-                                        .addGroup(layout.createParallelGroup(Alignment.LEADING)
-                                                .addComponent(labelGotoLine)
-                                                .addComponent(labelNumerotation))
-                                                .addGap(18, 18, 18)
-                                                .addGroup(layout.createParallelGroup(Alignment.LEADING)
-                                                        .addComponent(lineNumber, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
-                                                        .addComponent(numType, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
-                                                        .addContainerGap())
-                );
+                                  .addGroup(layout.createSequentialGroup()
+                                            .addContainerGap()
+                                            .addGroup(layout.createParallelGroup(Alignment.LEADING)
+                                                    .addComponent(scrollPane, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
+                                                    .addComponent(jSeparator1, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
+                                                    .addGroup(layout.createSequentialGroup()
+                                                            .addGroup(layout.createParallelGroup(Alignment.LEADING)
+                                                                    .addComponent(labelGotoLine)
+                                                                    .addComponent(labelNumerotation))
+                                                            .addGap(18, 18, 18)
+                                                            .addGroup(layout.createParallelGroup(Alignment.LEADING)
+                                                                    .addComponent(lineNumber, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
+                                                                    .addComponent(numType, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
+                                            .addContainerGap())
+                                 );
         layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING)
-                .addGroup(Alignment.TRAILING, layout.createSequentialGroup()
-                        .addContainerGap()
-                        .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
-                        .addPreferredGap(ComponentPlacement.RELATED)
-                        .addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
-                        .addPreferredGap(ComponentPlacement.RELATED)
-                        .addGroup(layout.createParallelGroup(Alignment.BASELINE)
-                                .addComponent(labelGotoLine)
-                                .addComponent(lineNumber, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
-                                .addGap(4, 4, 4)
-                                .addGroup(layout.createParallelGroup(Alignment.BASELINE)
-                                        .addComponent(labelNumerotation)
-                                        .addComponent(numType, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
-                                        .addContainerGap())
-                );
+                                .addGroup(Alignment.TRAILING, layout.createSequentialGroup()
+                                          .addContainerGap()
+                                          .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
+                                          .addPreferredGap(ComponentPlacement.RELATED)
+                                          .addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
+                                          .addPreferredGap(ComponentPlacement.RELATED)
+                                          .addGroup(layout.createParallelGroup(Alignment.BASELINE)
+                                                  .addComponent(labelGotoLine)
+                                                  .addComponent(lineNumber, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                          .addGap(4, 4, 4)
+                                          .addGroup(layout.createParallelGroup(Alignment.BASELINE)
+                                                  .addComponent(labelNumerotation)
+                                                  .addComponent(numType, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                          .addContainerGap())
+                               );
         /* End NetBeans */
 
         List<Component> components = new ArrayList(3);
@@ -526,7 +526,7 @@ TreeExpansionListener {
         fileMenu.setMnemonic('F');
         MenuItem menu = ScilabMenuItem.createMenuItem();
         menu.setCallback(callback);
-        ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(SciNotesGUI.getActionKeyMap().get("ExitAction"));
+        ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(SciNotes.getActionKeys().get("scinotes-exit"));
         menu.setText(SciNotesMessages.EXIT);
         fileMenu.add(menu);
         menubar.add(fileMenu);
index 587ae25..e1de156 100644 (file)
@@ -74,9 +74,9 @@ import org.scilab.modules.scinotes.actions.SaveAction;
  * @author Calixte DENIZET
  */
 public class ScilabTabbedPane extends JTabbedPane implements DragGestureListener,
-                                                  DragSourceListener,
-                                                  DropTargetListener,
-                                                  Transferable {
+    DragSourceListener,
+    DropTargetListener,
+    Transferable {
 
     private static final ImageIcon CLOSEICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/close-tab.png");
     private static final ImageIcon CLOSEONICON = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/close-tab-on.png");
@@ -102,13 +102,13 @@ public class ScilabTabbedPane extends JTabbedPane implements DragGestureListener
         super();
         this.editor = editor;
         setFocusTraversalPolicy(new java.awt.DefaultFocusTraversalPolicy() {
-                public Component getComponentAfter(Container aContainer, Component aComponent) {
-                    if (aComponent instanceof ScilabEditorPane) {
-                        return aComponent;
-                    }
-                    return super.getComponentAfter(aContainer, aComponent);
+            public Component getComponentAfter(Container aContainer, Component aComponent) {
+                if (aComponent instanceof ScilabEditorPane) {
+                    return aComponent;
                 }
-            });
+                return super.getComponentAfter(aContainer, aComponent);
+            }
+        });
 
         setFocusCycleRoot(true);
 
@@ -117,14 +117,14 @@ public class ScilabTabbedPane extends JTabbedPane implements DragGestureListener
         dragsource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this);
         DropTarget droptarget = new DropTarget(this, this);
         addMouseListener(new MouseAdapter() {
-                public void mouseClicked(MouseEvent e) {
-                    if (e.getClickCount() == 1 && SwingUtilities.isMiddleMouseButton(e)) {
-                        int index = indexAtLocation(e.getX(), e.getY());
-                        ((CloseTabButton) getTabComponentAt(index)).closeTab();
-                        e.consume();
-                    }
+            public void mouseClicked(MouseEvent e) {
+                if (e.getClickCount() == 1 && SwingUtilities.isMiddleMouseButton(e)) {
+                    int index = indexAtLocation(e.getX(), e.getY());
+                    ((CloseTabButton) getTabComponentAt(index)).closeTab();
+                    e.consume();
                 }
-            });
+            }
+        });
     }
 
     /**
@@ -184,7 +184,7 @@ public class ScilabTabbedPane extends JTabbedPane implements DragGestureListener
      * @return the supported flavors
      */
     public DataFlavor[] getTransferDataFlavors() {
-        return new DataFlavor[]{DATAFLAVOR};
+        return new DataFlavor[] {DATAFLAVOR};
     }
 
     /**
@@ -375,45 +375,44 @@ public class ScilabTabbedPane extends JTabbedPane implements DragGestureListener
      */
     private JPopupMenu createPopupMenu() {
         JPopupMenu popup = new JPopupMenu() {
-                public void show(Component invoker, int x, int y) {
-                    int index = ScilabTabbedPane.this.indexAtLocation(x, y);
-                    ScilabTabbedPane.this.setSelectedIndex(index);
-                    super.show(invoker, x, y);
-                }
-            };
+            public void show(Component invoker, int x, int y) {
+                int index = ScilabTabbedPane.this.indexAtLocation(x, y);
+                ScilabTabbedPane.this.setSelectedIndex(index);
+                super.show(invoker, x, y);
+            }
+        };
 
-        Map<String, KeyStroke> map = new HashMap<String, KeyStroke>();
-        ConfigSciNotesManager.addMapActionNameKeys(map);
+        Map<String, KeyStroke> map = SciNotes.getActionKeys();
 
         SwingScilabMenuItem menuItem;
-        menuItem = (SwingScilabMenuItem) SaveAction.createMenu(SciNotesMessages.SAVE, editor, map.get("SaveAction")).getAsSimpleMenuItem();
+        menuItem = (SwingScilabMenuItem) SaveAction.createMenu(SciNotesMessages.SAVE, editor, map.get("scinotes-save")).getAsSimpleMenuItem();
         popup.add(menuItem);
 
-        menuItem = (SwingScilabMenuItem) CloseAction.createMenu(SciNotesMessages.CLOSE, editor, map.get("CloseAction")).getAsSimpleMenuItem();
+        menuItem = (SwingScilabMenuItem) CloseAction.createMenu(SciNotesMessages.CLOSE, editor, map.get("scinotes-close")).getAsSimpleMenuItem();
         popup.add(menuItem);
 
-        menuItem = (SwingScilabMenuItem) CloseAllButThisAction.createMenu(SciNotesMessages.CLOSEALLBUTTHIS, editor, map.get("CloseAllButThisAction")).getAsSimpleMenuItem();
+        menuItem = (SwingScilabMenuItem) CloseAllButThisAction.createMenu(SciNotesMessages.CLOSEALLBUTTHIS, editor, map.get("scinotes-close-all-but")).getAsSimpleMenuItem();
         popup.add(menuItem);
 
         popup.addSeparator();
 
         final JMenuItem menuitem = new JMenuItem(SciNotesMessages.COPYFULLFILEPATH);
         menuitem.addActionListener(new ActionListener() {
-                public void actionPerformed(ActionEvent actionEvent) {
-                    if (editor.getTextPane() != null) {
-                        StringSelection sel = new StringSelection(editor.getTextPane().getName());
-                        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel);
-                    }
+            public void actionPerformed(ActionEvent actionEvent) {
+                if (editor.getTextPane() != null) {
+                    StringSelection sel = new StringSelection(editor.getTextPane().getName());
+                    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel);
                 }
-            });
+            }
+        });
         menuitem.addPropertyChangeListener(new PropertyChangeListener() {
-                public void propertyChange(PropertyChangeEvent e) {
-                    if (editor.getTextPane() != null) {
-                        String name = editor.getTextPane().getName();
-                        menuitem.setEnabled(name != null && !name.isEmpty());
-                    }
+            public void propertyChange(PropertyChangeEvent e) {
+                if (editor.getTextPane() != null) {
+                    String name = editor.getTextPane().getName();
+                    menuitem.setEnabled(name != null && !name.isEmpty());
                 }
-            });
+            }
+        });
         popup.add(menuitem);
 
         return popup;
@@ -483,10 +482,10 @@ public class ScilabTabbedPane extends JTabbedPane implements DragGestureListener
                 setBorderPainted(false);
                 setContentAreaFilled(false);
                 addActionListener(new ActionListener() {
-                        public void actionPerformed(ActionEvent e) {
-                            closeTab();
-                        }
-                    });
+                    public void actionPerformed(ActionEvent e) {
+                        closeTab();
+                    }
+                });
             }
         }
     }
index a90009c..f176867 100644 (file)
@@ -262,8 +262,8 @@ public class SearchFile extends SwingScilabTab {
     }
 
     public void fillTab(SearchManager.MatchingPositions pos, String base, boolean recursive, boolean ignoreCR,
-            String filePattern, boolean fileCaseSensitive, String wordPattern,
-            boolean wordCaseSensitive, boolean wholeWord, boolean regexp) {
+                        String filePattern, boolean fileCaseSensitive, String wordPattern,
+                        boolean wordCaseSensitive, boolean wholeWord, boolean regexp) {
         String title;
 
         if (wordPattern == null || wordPattern.isEmpty()) {
@@ -322,7 +322,7 @@ public class SearchFile extends SwingScilabTab {
         fileMenu.setMnemonic('F');
         MenuItem menu = ScilabMenuItem.createMenuItem();
         menu.setCallback(callback);
-        ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(SciNotesGUI.getActionKeyMap().get("ExitAction"));
+        ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(SciNotes.getActionKeys().get("scinotes-exit"));
         menu.setText(SciNotesMessages.EXIT);
         fileMenu.add(menu);
         menubar.add(fileMenu);
@@ -356,9 +356,9 @@ public class SearchFile extends SwingScilabTab {
      * @return the corresponding JTree
      */
     public static JTree getJTree(SearchManager.MatchingPositions files, final SciNotes editor, final TextBox statusbar,
-