Bug 11834 fixed: In SciNotes, there was no menu to set font or colors 36/8936/3
Calixte DENIZET [Wed, 5 Sep 2012 09:20:20 +0000 (11:20 +0200)]
Change-Id: I1a04fa040d0be65e6cce16b86a72148cda7a1acc

12 files changed:
scilab/CHANGES_5.4.X
scilab/modules/commons/src/java/org/scilab/modules/commons/ScilabGeneralPrefs.java
scilab/modules/console/etc/Actions-Configuration.xml
scilab/modules/console/etc/XConfiguration-general.xml
scilab/modules/preferences/etc/XConfiguration.xml
scilab/modules/preferences/src/java/org/scilab/modules/preferences/ScilabPreferences.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/scinotes/etc/XConfiguration-scinotes.xsl
scilab/modules/scinotes/etc/scinotesGUIConfiguration.xml
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/SetColorsAction.java [new file with mode: 0644]
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/SetFontAction.java [new file with mode: 0644]

index 7939ae0..02dbf28 100644 (file)
@@ -41,6 +41,8 @@ Bug Fixes
 * Bug #11810 fixed - In BrowseVar, contents of "visibility" column are left
                      aligned.
 
+* Bug #11834 fixed - In SciNotes there was not a menu to set font or colors.
+
 * Bug #11840 fixed - In Xcos, dialogs could not be closed on escape.
 
 
index 2866165..23d5d44 100644 (file)
@@ -13,6 +13,8 @@
 package org.scilab.modules.commons;
 
 import java.awt.Font;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 
 import org.w3c.dom.Document;
 
@@ -37,6 +39,18 @@ public class ScilabGeneralPrefs implements XConfigurationListener {
         return instance;
     }
 
+    public static void openPreferences(String path) {
+        try {
+            Class prefs = ClassLoader.getSystemClassLoader().loadClass("org.scilab.modules.preferences.ScilabPreferences");
+            Method open = prefs.getDeclaredMethod("openPreferences", String.class);
+            open.invoke(null, path);
+        } catch (ClassNotFoundException e) {
+            // Nothing displayed (always occurs in MN mode)
+        } catch (Exception e) {
+            System.err.println(e);
+        }
+    }
+
     public void configurationChanged(XConfigurationEvent e) {
         boolean all = e.getModifiedPaths().contains("ALL");
         if (all || e.getModifiedPaths().contains(ENV_PATH)) {
@@ -50,7 +64,7 @@ public class ScilabGeneralPrefs implements XConfigurationListener {
             Document doc = XConfiguration.getXConfigurationDocument();
             Language language = XConfiguration.get(Language.class, doc, LANG_PATH)[0];
             WindowsDefaultLanguage.setdefaultlanguage(language.lang);
-       }
+        }
 
         if (all || e.getModifiedPaths().contains(FONT_PATH)) {
             desktopFont = null;
index e7e7e53..7f678ec 100644 (file)
@@ -80,6 +80,8 @@
     <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"/>
+    <entry type="java" action="SetFontAction" name="scinotes-set-font"/>
+    <entry type="java" action="SetColorsAction" name="scinotes-set-colors"/>
   </scinotes>
   <console>
     <entry type="java" action="org.scilab.modules.console.SelectAllAction" name="console-select-all"/>
index ad4ef3a..5c4b225 100644 (file)
                     <action key="" description="_(Close all but this)" 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="_(Set the SciNotes font)" name="scinotes-set-font"/>
+                    <action key="" description="_(Set the SciNotes colors)" name="scinotes-set-colors"/>
                 </action-folder>
                 <action-folder name="Xcos" xconf-uid="xcos">
                     <!-- File -->
index 010f7f5..db4db96 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<interface version="0.07" path="1/" width="800" height="550">
+<interface version="0.08" path="1/" width="800" height="550">
     <general/>
     <web/>
     <preference/>
index ad0b9af..8035567 100644 (file)
@@ -33,11 +33,18 @@ public class ScilabPreferences {
      * Open the preferences window
      */
     public static void openPreferences() {
+        openPreferences(null);
+    }
+
+    /**
+     * Open the preferences window
+     */
+    public static void openPreferences(final String initialPath) {
         SwingUtilities.invokeLater(new Runnable() {
-            public void run() {
-                XConfigManager.openPreferences();
-            }
-        });
+                public void run() {
+                    XConfigManager.openPreferences(initialPath);
+                }
+            });
     }
 
     /**
index deebb65..d255914 100644 (file)
@@ -142,34 +142,34 @@ public abstract class XCommonManager {
     static {
         factory = ScilabTransformerFactory.newInstance();
         factory.setURIResolver(new URIResolver() {
-            public Source resolve(String href, String base) throws TransformerException {
-                if (href.startsWith("$SCI")) {
-                    href = href.replace("$SCI", SCI);
-                    base = null;
-                }
-
-                try {
-                    File baseDir = null;
-                    if (base != null && !base.isEmpty()) {
-                        baseDir = new File(new URI(base)).getParentFile();
-                    }
-                    File f;
-                    if (baseDir != null) {
-                        f = new File(baseDir, href);
-                    } else {
-                        f = new File(href);
+                public Source resolve(String href, String base) throws TransformerException {
+                    if (href.startsWith("$SCI")) {
+                        href = href.replace("$SCI", SCI);
+                        base = null;
                     }
 
-                    if (f.exists() && f.canRead()) {
-                        return new StreamSource(f);
+                    try {
+                        File baseDir = null;
+                        if (base != null && !base.isEmpty()) {
+                            baseDir = new File(new URI(base)).getParentFile();
+                        }
+                        File f;
+                        if (baseDir != null) {
+                            f = new File(baseDir, href);
+                        } else {
+                            f = new File(href);
+                        }
+
+                        if (f.exists() && f.canRead()) {
+                            return new StreamSource(f);
+                        }
+                    } catch (Exception e) {
+                        System.out.println(e);
                     }
-                } catch (Exception e) {
-                    System.out.println(e);
-                }
 
-                throw new TransformerException("Cannot find the file " + href + "::" + base);
-            }
-        });
+                    throw new TransformerException("Cannot find the file " + href + "::" + base);
+                }
+            });
     }
 
     /**
@@ -276,10 +276,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/");
@@ -306,10 +306,10 @@ public abstract class XCommonManager {
             buffer.append("<xsl:import href=\"").append(SCI).append("/modules/preferences/src/xslt/XConfiguration.xsl").append("\"/>\n");
 
             FilenameFilter filter = 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");
+                    }
+                };
 
             // Include standard Scilab xsl files
             for (File etc : etcs) {
@@ -326,10 +326,10 @@ public abstract class XCommonManager {
             // Include toolboxes xsl files
             List<ScilabPreferences.ToolboxInfos> infos = ScilabPreferences.getToolboxesInfos();
             filter = new FilenameFilter() {
-                public boolean accept(File dir, String name) {
-                    return name.endsWith(".xsl");
-                }
-            };
+                    public boolean accept(File dir, String name) {
+                        return name.endsWith(".xsl");
+                    }
+                };
             for (ScilabPreferences.ToolboxInfos i : infos) {
                 File etc = new File(i.getPrefFile()).getParentFile();
                 File[] xsls = etc.listFiles(filter);
@@ -421,6 +421,42 @@ public abstract class XCommonManager {
     }
 
     /**
+     * Get the real path from an abstract path: scinotes/header will be converted into 8/2
+     * @param name abstract path
+     * @return real path
+     */
+    public static String getPath(String name) {
+        String[] ids = name.split("/");
+        Element element = document.getDocumentElement();
+        String path = "";
+        for (int i = 0; i < ids.length; i++) {
+            int index = 1;
+            NodeList childNodes = element.getChildNodes();
+            Node node = null;
+            int len = childNodes.getLength();
+            int j = 0;
+            for (; j < len; j++) {
+                node = childNodes.item(j);
+                String nodeName = node.getNodeName();
+                if (nodeName.equalsIgnoreCase(ids[i])) {
+                    path += index + "/";
+                    element = (Element) node;
+                    break;
+                }
+                if (!node.getNodeName().equals("#text") && !node.getNodeName().equals("#comment")) {
+                    index++;
+                }
+            }
+
+            if (j == len) {
+                System.err.println("Invalid path: " + name);
+                return "1/";
+            }
+        }
+        return path;
+    }
+
+    /**
      * Interpret action.
      * @param action : to be interpreted.
      * @param source : component source of the action (only class is needed).
@@ -443,6 +479,9 @@ public abstract class XCommonManager {
                 Element element = getElementByContext(context);
                 String value = getAttribute(action, "value");
                 String attribute = getAttribute(action, "set");
+                if (attribute.equals("path") && context.equals("/") && !Character.isDigit(value.charAt(0))) {
+                    value = getPath(value);
+                }
                 if (element != null) {
                     element.setAttribute(attribute, value);
                     XConfiguration.addModifiedPath(getNodePath(element));
@@ -674,10 +713,10 @@ public abstract class XCommonManager {
             return NAV;
         }
 
-       String response = attr.getNodeValue();
-       if (response.startsWith("_(") && response.endsWith(")")) {
-           response = Messages.gettext(response.substring(2, response.length() - 1));
-       }
+        String response = attr.getNodeValue();
+        if (response.startsWith("_(") && response.endsWith(")")) {
+            response = Messages.gettext(response.substring(2, response.length() - 1));
+        }
 
         return response;
     }
index 9e82ac4..a2b6e4d 100644 (file)
@@ -84,7 +84,7 @@ public final class XConfigManager extends XCommonManager {
     /** Display dialog and wait for events.
      *
      */
-    public static void displayAndWait() {
+    public static void displayAndWait(String initialPath) {
         XConfigManager.active = true;
         XWizardManager.active = false;
 
@@ -99,29 +99,33 @@ public final class XConfigManager extends XCommonManager {
 
         // Set up DOM Side
         readUserDocuments();
+        if (initialPath != null && !initialPath.equals("")) {
+            String path = getPath(initialPath);
+            document.getDocumentElement().setAttribute("path", path);
+        }
         updated = false;
 
         // Plug in resize
         //dialog.setResizable(false);
         dialog.addComponentListener(new ComponentAdapter() {
-            public void componentResized(ComponentEvent e) {
-                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()));
+                public void componentResized(ComponentEvent e) {
+                    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.addWindowListener(new WindowAdapter() {
-            @Override
-            public void windowClosing(WindowEvent e) {
-                cancel();
-            }
-        });
+                @Override
+                public void windowClosing(WindowEvent e) {
+                    cancel();
+                }
+            });
         ScilabSwingUtilities.closeOnEscape(dialog);
 
         // Set up correspondence
@@ -143,8 +147,8 @@ public final class XConfigManager extends XCommonManager {
     /**
      * Opens a dialog to setup preferences.
      */
-    public static void openPreferences() {
-        XConfigManager.displayAndWait();
+    public static void openPreferences(String initialPath) {
+        XConfigManager.displayAndWait(initialPath);
     }
 
     /** Secondary dialog for help.*/
@@ -247,8 +251,8 @@ public final class XConfigManager extends XCommonManager {
             Element tbxs = (Element) toolboxes.item(0);
             document.getDocumentElement().removeChild(tbxs);
         }
+        correspondance = null;
         updated = false;
-        refreshDisplay();
     }
 
     /** Interpret action.
index 2ca56b0..90de849 100644 (file)
         </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
+          <mouseClicked set="path" value="scinotes/header" 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
index 2d218ce..9dc5da0 100644 (file)
       <menuitem action="scinotes-encoding" label="Current file encoding"/>
       <menuitem action="scinotes-eof" label="Line Endings"/>
       <separator/>
+      <menu label="Preferences">
+       <menuitem action="scinotes-set-font" label="Set font"/>
+       <menuitem action="scinotes-set-colors" label="Set colors"/>
+      </menu>
+      <separator/>
       <menu label="Auto-completion on">
         <menuitem action="scinotes-autocomplete-openers" label="(, [, ..."/>
         <menuitem action="scinotes-autocomplete-keyword" label="if, function, ..."/>
diff --git a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/SetColorsAction.java b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/SetColorsAction.java
new file mode 100644 (file)
index 0000000..faf4a27
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.actions;
+
+import javax.swing.KeyStroke;
+
+import org.scilab.modules.commons.ScilabGeneralPrefs;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.scinotes.SciNotes;
+
+/**
+ * SetColorsAction Class
+ * @author Calixte DENIZET
+ */
+public class SetColorsAction extends DefaultAction {
+
+    /**
+     * Constructor
+     * @param name the name of the action
+     * @param editor SciNotes
+     */
+    public SetColorsAction(String name, SciNotes editor) {
+        super(name, editor);
+    }
+
+    /**
+     * doAction
+     */
+    @Override
+    public void doAction() {
+        ScilabGeneralPrefs.openPreferences("colors/");
+    }
+
+    /**
+     * createMenu
+     * @param label label of the menu
+     * @param editor SciNotes
+     * @param key Keystroke
+     * @return MenuItem
+     */
+    public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
+        return createMenu(label, null, new SetColorsAction(label, editor), key);
+    }
+}
diff --git a/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/SetFontAction.java b/scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/SetFontAction.java
new file mode 100644 (file)
index 0000000..f98e523
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.actions;
+
+import javax.swing.KeyStroke;
+
+import org.scilab.modules.commons.ScilabGeneralPrefs;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.scinotes.SciNotes;
+
+/**
+ * SetFontAction Class
+ * @author Calixte DENIZET
+ */
+public class SetFontAction extends DefaultAction {
+
+    /**
+     * Constructor
+     * @param name the name of the action
+     * @param editor SciNotes
+     */
+    public SetFontAction(String name, SciNotes editor) {
+        super(name, editor);
+    }
+
+    /**
+     * doAction
+     */
+    @Override
+    public void doAction() {
+        ScilabGeneralPrefs.openPreferences("fonts/");
+    }
+
+    /**
+     * createMenu
+     * @param label label of the menu
+     * @param editor SciNotes
+     * @param key Keystroke
+     * @return MenuItem
+     */
+    public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
+        return createMenu(label, null, new SetFontAction(label, editor), key);
+    }
+}