Preferences: can choose a desktop layout 20/7620/11
Calixte DENIZET [Wed, 20 Jun 2012 13:55:45 +0000 (15:55 +0200)]
Change-Id: I3b881b5799cfd68d98f0aaa365206f3981b40a85

scilab/modules/console/etc/XConfiguration-general.xml
scilab/modules/console/etc/XConfiguration-general.xsl
scilab/modules/gui/Makefile.am
scilab/modules/gui/Makefile.in
scilab/modules/gui/etc/integratedConfiguration.xml [moved from scilab/modules/gui/etc/windowsConfiguration.xml with 100% similarity]
scilab/modules/gui/etc/simpleConfiguration.xml [new file with mode: 0644]
scilab/modules/gui/gui.iss
scilab/modules/gui/images/preferences/integrated.png [new file with mode: 0644]
scilab/modules/gui/images/preferences/simple.png [new file with mode: 0644]
scilab/modules/gui/src/java/org/scilab/modules/gui/utils/WindowsConfigurationManager.java
scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/Image.java [new file with mode: 0644]

index 0d8a5cc..ee54cfb 100644 (file)
       </tools>
     </body>
   </confirmation-dialogs>
+  <desktop-layout title="Desktop layout">
+    <body>
+      <layouts name="Integrated">
+        <layout name="Integrated" path="$SCI/modules/gui/etc/integratedConfiguration.xml" image="file:///$SCI/modules/gui/images/preferences/integrated.png"/>
+        <layout name="Simple" path="$SCI/modules/gui/etc/simpleConfiguration.xml" image="file:///$SCI/modules/gui/images/preferences/simple.png"/>
+      </layouts>
+    </body>
+  </desktop-layout>
   <shortcuts title="Shortcuts">
     <body>
       <actions active="scilab" name="Console" item="1" browse="--choose a file --" filter="">
index 3ca51f8..6d6ab6d 100644 (file)
@@ -71,7 +71,7 @@
             <xsl:call-template name="context"/>\r
           </actionPerformed>\r
         </NumericalSpinner>\r
-        <Label text="(modify this option requires to restart Scilab)" font-face="bold" gridx="1" gridy="2" anchor="west" weightx="0"/>\r
+        <Label text="(This requires a restart of Scilab)" font-face="bold" gridx="1" gridy="2" anchor="west" weightx="0"/>\r
        <Panel gridx="2" gridy="2" weightx="1" fill="both"/>    \r
       </Grid>\r
     </Title>\r
   </xsl:template>\r
 \r
   <xsl:template match="tools">\r
-      <Title text="Confirmation dialogs">\r
-        <Grid>\r
-          <xsl:for-each select="tool">\r
-            <Checkbox\r
-                gridy    = "{position() + 1}"\r
-                gridx    = "1"\r
-                listener = "ActionListener"\r
-                checked  = "{@state}"\r
-                text     = "{@description}">\r
-              <actionPerformed choose="state">\r
-                <xsl:call-template name="context"/>\r
-              </actionPerformed>\r
-            </Checkbox>\r
-          </xsl:for-each>\r
-        </Grid>\r
-      </Title>\r
+    <Title text="Confirmation dialogs">\r
+      <Grid>\r
+        <xsl:for-each select="tool">\r
+          <Checkbox\r
+              gridy    = "{position() + 1}"\r
+              gridx    = "1"\r
+              listener = "ActionListener"\r
+              checked  = "{@state}"\r
+              text     = "{@description}">\r
+            <actionPerformed choose="state">\r
+              <xsl:call-template name="context"/>\r
+            </actionPerformed>\r
+          </Checkbox>\r
+        </xsl:for-each>\r
+      </Grid>\r
+    </Title>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="layouts">\r
+    <xsl:variable name="name" select="@name"/>\r
+    <Title text="Desktop Layout">\r
+      <Grid>\r
+        <Label gridx="1" gridy="1" weightx="0" text="Select a layout"/>\r
+        <Panel gridx="2" gridy="1" gridheight="1" fill="both"/>\r
+        <Panel gridx="3" gridy="1">\r
+          <xsl:call-template name="Select">\r
+            <xsl:with-param name="among">\r
+              <xsl:for-each select="layout">\r
+                <option name="{@name}"/>\r
+              </xsl:for-each>\r
+            </xsl:with-param>\r
+          </xsl:call-template>\r
+        </Panel>\r
+       <Label text="(modify the layout requires to restart Scilab)" font-face="bold" gridx="1" gridy="2" anchor="west" weightx="0"/>\r
+       <Panel gridx="1" gridy="3">\r
+         <VSpace height="10"/>\r
+       </Panel>\r
+        <Image gridx="1" gridy="4" gridwidth="3">\r
+          <xsl:attribute name="url">\r
+            <xsl:value-of select="layout[@name=$name]/@image"/>\r
+          </xsl:attribute>\r
+        </Image>\r
+       \r
+      </Grid>\r
+    </Title>\r
   </xsl:template>\r
 \r
   <xsl:template match="actions">\r
index 24555aa..4a19c60 100644 (file)
@@ -33,7 +33,8 @@ libscigui_la_etc_DATA = \
        etc/main_menubar.xml \
        etc/main_toolbar.xml \
        etc/flexdock-themes.xml \
-       etc/windowsConfiguration.xml \
+       etc/integratedConfiguration.xml \
+       etc/simpleConfiguration.xml \
        etc/XConfiguration-colors.xml \
        etc/XConfiguration-colors.xsl \
        etc/XConfiguration-font.xml \
@@ -395,7 +396,10 @@ images/icons/rotate.png \
 images/icons/scilab_close_active.png \
 images/icons/scilab_close_default.png \
 images/icons/undock_active.png \
-images/icons/undock_default.png
+images/icons/undock_default.png \
+images/preferences/integrated.png \
+images/preferences/simple.png
+
 
 if GUI
 USEANT=1
index 8426538..2890939 100644 (file)
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.11.3 from Makefile.am.
+# Makefile.in generated by automake 1.11.5 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
 
 
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -283,6 +300,11 @@ SOURCES = $(libscigui_algo_la_SOURCES) $(libscigui_disable_la_SOURCES) \
        $(libscigui_la_SOURCES)
 DIST_SOURCES = $(libscigui_algo_la_SOURCES) \
        $(libscigui_disable_la_SOURCES) $(libscigui_la_SOURCES)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 DATA = $(libscigui_la_etc_DATA) $(libscigui_la_root_DATA) \
        $(libscigui_la_sci_gateway_DATA) \
        $(nobase_libscigui_la_icons_DATA)
@@ -561,7 +583,8 @@ libscigui_la_etc_DATA = \
        etc/main_menubar.xml \
        etc/main_toolbar.xml \
        etc/flexdock-themes.xml \
-       etc/windowsConfiguration.xml \
+       etc/integratedConfiguration.xml \
+       etc/simpleConfiguration.xml \
        etc/XConfiguration-colors.xml \
        etc/XConfiguration-colors.xsl \
        etc/XConfiguration-font.xml \
@@ -904,7 +927,9 @@ images/icons/rotate.png \
 images/icons/scilab_close_active.png \
 images/icons/scilab_close_default.png \
 images/icons/undock_active.png \
-images/icons/undock_default.png
+images/icons/undock_default.png \
+images/preferences/integrated.png \
+images/preferences/simple.png
 
 @GUI_TRUE@USEANT = 1
 
@@ -1027,7 +1052,6 @@ clean-noinstLTLIBRARIES:
        done
 install-pkglibLTLIBRARIES: $(pkglib_LTLIBRARIES)
        @$(NORMAL_INSTALL)
-       test -z "$(pkglibdir)" || $(MKDIR_P) "$(DESTDIR)$(pkglibdir)"
        @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || list=; \
        list2=; for p in $$list; do \
          if test -f $$p; then \
@@ -1035,6 +1059,8 @@ install-pkglibLTLIBRARIES: $(pkglib_LTLIBRARIES)
          else :; fi; \
        done; \
        test -z "$$list2" || { \
+         echo " $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(pkglibdir)" || exit 1; \
          echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(pkglibdir)'"; \
          $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(pkglibdir)"; \
        }
@@ -2215,8 +2241,11 @@ clean-libtool:
        -rm -rf .libs _libs
 install-libscigui_la_etcDATA: $(libscigui_la_etc_DATA)
        @$(NORMAL_INSTALL)
-       test -z "$(libscigui_la_etcdir)" || $(MKDIR_P) "$(DESTDIR)$(libscigui_la_etcdir)"
        @list='$(libscigui_la_etc_DATA)'; test -n "$(libscigui_la_etcdir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(libscigui_la_etcdir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(libscigui_la_etcdir)" || exit 1; \
+       fi; \
        for p in $$list; do \
          if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
          echo "$$d$$p"; \
@@ -2233,8 +2262,11 @@ uninstall-libscigui_la_etcDATA:
        dir='$(DESTDIR)$(libscigui_la_etcdir)'; $(am__uninstall_files_from_dir)
 install-libscigui_la_rootDATA: $(libscigui_la_root_DATA)
        @$(NORMAL_INSTALL)
-       test -z "$(libscigui_la_rootdir)" || $(MKDIR_P) "$(DESTDIR)$(libscigui_la_rootdir)"
        @list='$(libscigui_la_root_DATA)'; test -n "$(libscigui_la_rootdir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(libscigui_la_rootdir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(libscigui_la_rootdir)" || exit 1; \
+       fi; \
        for p in $$list; do \
          if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
          echo "$$d$$p"; \
@@ -2251,8 +2283,11 @@ uninstall-libscigui_la_rootDATA:
        dir='$(DESTDIR)$(libscigui_la_rootdir)'; $(am__uninstall_files_from_dir)
 install-libscigui_la_sci_gatewayDATA: $(libscigui_la_sci_gateway_DATA)
        @$(NORMAL_INSTALL)
-       test -z "$(libscigui_la_sci_gatewaydir)" || $(MKDIR_P) "$(DESTDIR)$(libscigui_la_sci_gatewaydir)"
        @list='$(libscigui_la_sci_gateway_DATA)'; test -n "$(libscigui_la_sci_gatewaydir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(libscigui_la_sci_gatewaydir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(libscigui_la_sci_gatewaydir)" || exit 1; \
+       fi; \
        for p in $$list; do \
          if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
          echo "$$d$$p"; \
@@ -2269,15 +2304,18 @@ uninstall-libscigui_la_sci_gatewayDATA:
        dir='$(DESTDIR)$(libscigui_la_sci_gatewaydir)'; $(am__uninstall_files_from_dir)
 install-nobase_libscigui_la_iconsDATA: $(nobase_libscigui_la_icons_DATA)
        @$(NORMAL_INSTALL)
-       test -z "$(libscigui_la_iconsdir)" || $(MKDIR_P) "$(DESTDIR)$(libscigui_la_iconsdir)"
        @list='$(nobase_libscigui_la_icons_DATA)'; test -n "$(libscigui_la_iconsdir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(libscigui_la_iconsdir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(libscigui_la_iconsdir)" || exit 1; \
+       fi; \
        $(am__nobase_list) | while read dir files; do \
          xfiles=; for file in $$files; do \
            if test -f "$$file"; then xfiles="$$xfiles $$file"; \
            else xfiles="$$xfiles $(srcdir)/$$file"; fi; done; \
          test -z "$$xfiles" || { \
            test "x$$dir" = x. || { \
-             echo "$(MKDIR_P) '$(DESTDIR)$(libscigui_la_iconsdir)/$$dir'"; \
+             echo " $(MKDIR_P) '$(DESTDIR)$(libscigui_la_iconsdir)/$$dir'"; \
              $(MKDIR_P) "$(DESTDIR)$(libscigui_la_iconsdir)/$$dir"; }; \
            echo " $(INSTALL_DATA) $$xfiles '$(DESTDIR)$(libscigui_la_iconsdir)/$$dir'"; \
            $(INSTALL_DATA) $$xfiles "$(DESTDIR)$(libscigui_la_iconsdir)/$$dir" || exit $$?; }; \
diff --git a/scilab/modules/gui/etc/simpleConfiguration.xml b/scilab/modules/gui/etc/simpleConfiguration.xml
new file mode 100644 (file)
index 0000000..f171b61
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<Scilab>
+  <Console factory="org.scilab.modules.core.ConsoleTabFactory" load="Console" uuid="00000000-0000-0000-0000-000000000000" winuuid="5171ff0a-e5e6-4ea9-8525-8d9a5434b881"/>
+</Scilab>
index 6e2c873..d4377b7 100644 (file)
@@ -39,6 +39,7 @@ Source: modules\{#GUI}\etc\{#GUI}.start; DestDir: {app}\modules\{#GUI}\etc; Comp
 Source: modules\{#GUI}\etc\*.xml; DestDir: {app}\modules\{#GUI}\etc; Components: {#COMPN_SCILAB} and {#COMPN_JVM_MODULE}
 Source: modules\{#GUI}\etc\*.xsl; DestDir: {app}\modules\{#GUI}\etc; Components: {#COMPN_SCILAB} and {#COMPN_JVM_MODULE}
 Source: modules\{#GUI}\images\icons\*.png; DestDir: {app}\modules\{#GUI}\images\icons; Flags: recursesubdirs; Components: {#COMPN_SCILAB} and {#COMPN_JVM_MODULE}
+Source: modules\{#GUI}\images\preferences\*.png; DestDir: {app}\modules\{#GUI}\images\preferences; Flags: recursesubdirs; Components: {#COMPN_SCILAB} and {#COMPN_JVM_MODULE}
 ;
 ;Source: modules\{#GUI}\includes\*.h; DestDir: {app}\modules\{#GUI}\includes; Components: {#COMPN_SCILAB} and {#COMPN_JVM_MODULE}
 ;
diff --git a/scilab/modules/gui/images/preferences/integrated.png b/scilab/modules/gui/images/preferences/integrated.png
new file mode 100644 (file)
index 0000000..b187ac0
Binary files /dev/null and b/scilab/modules/gui/images/preferences/integrated.png differ
diff --git a/scilab/modules/gui/images/preferences/simple.png b/scilab/modules/gui/images/preferences/simple.png
new file mode 100644 (file)
index 0000000..5f44a42
Binary files /dev/null and b/scilab/modules/gui/images/preferences/simple.png differ
index 46074c5..ab18a43 100644 (file)
@@ -38,6 +38,10 @@ import org.flexdock.perspective.persist.xml.PersistenceConstants;
 import org.scilab.modules.commons.ScilabCommons;
 import org.scilab.modules.commons.ScilabCommonsUtils;
 import org.scilab.modules.commons.xml.ScilabXMLUtilities;
+import org.scilab.modules.commons.xml.XConfiguration;
+import org.scilab.modules.commons.xml.XConfigurationEvent;
+import org.scilab.modules.commons.xml.XConfigurationListener;
+import org.scilab.modules.core.Scilab;
 import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
 import org.scilab.modules.gui.console.ScilabConsole;
@@ -55,13 +59,15 @@ import org.w3c.dom.NodeList;
  *
  * @author Calixte DENIZET
  */
-public class WindowsConfigurationManager {
+public class WindowsConfigurationManager implements XConfigurationListener {
 
     private static final int DEFAULTX = 0;
     private static final int DEFAULTY = 0;
     private static final int DEFAULTHEIGHT = 500;
     private static final int DEFAULTWIDTH = 500;
 
+    private static final String LAYOUT_PATH = "//general/desktop-layout/body/layouts";
+
     private static final String SCI = "SCI";
     private static final String WINDOWS_CONFIG_FILE = System.getenv(SCI) + "/modules/gui/etc/windowsConfiguration.xml";
     private static final String USER_WINDOWS_CONFIG_FILE = ScilabCommons.getSCIHOME() + "/windowsConfiguration.xml";
@@ -74,7 +80,21 @@ public class WindowsConfigurationManager {
     private static boolean oneTry;
     private static Document doc;
 
+    private static boolean mustInvalidate;
+
     static {
+        new WindowsConfigurationManager();
+        Scilab.registerFinalHook(new Runnable() {
+            public void run() {
+                if (mustInvalidate) {
+                    File f = new File(USER_WINDOWS_CONFIG_FILE);
+                    if (f.exists() && f.isFile()) {
+                        f.delete();
+                    }
+                }
+            }
+        });
+
         defaultWinAttributes.put("x", new Integer(DEFAULTX));
         defaultWinAttributes.put("y", new Integer(DEFAULTY));
         defaultWinAttributes.put("height", new Integer(DEFAULTHEIGHT));
@@ -86,12 +106,35 @@ public class WindowsConfigurationManager {
           }, java.awt.AWTEvent.FOCUS_EVENT_MASK);*/
     }
 
+    private WindowsConfigurationManager() {
+        XConfiguration.addXConfigurationListener(this);
+    }
+
+    public void configurationChanged(XConfigurationEvent e) {
+        if (e.getModifiedPaths().contains(LAYOUT_PATH)) {
+            mustInvalidate = true;
+        }
+    }
+
+    public static String getLayoutFilePath() {
+        try {
+            Document doc = XConfiguration.getXConfigurationDocument();
+            XPath xp = XPathFactory.newInstance().newXPath();
+            NodeList nodes = (NodeList) xp.compile(LAYOUT_PATH + "/layout[@name=../@name]/@path").evaluate(doc, XPathConstants.NODESET);
+            if (nodes != null && nodes.getLength() > 0) {
+                return nodes.item(0).getNodeValue().replace("$SCI", System.getenv(SCI));
+            }
+        } catch (Exception e) { }
+
+        return WINDOWS_CONFIG_FILE;
+    }
+
     /**
      * Create a copy of windows configuration file in the user directory
      */
     public static void createUserCopy() {
         if (isCopyNeeded()) {
-            ScilabCommonsUtils.copyFile(new File(WINDOWS_CONFIG_FILE), new File(USER_WINDOWS_CONFIG_FILE));
+            ScilabCommonsUtils.copyFile(new File(getLayoutFilePath()), new File(USER_WINDOWS_CONFIG_FILE));
             doc = null;
         }
     }
@@ -106,7 +149,7 @@ public class WindowsConfigurationManager {
         }
 
         if (doc == null && !oneTry) {
-            System.err.println("Try to reload the default configuration file: " + WINDOWS_CONFIG_FILE);
+            System.err.println("Try to reload the default configuration file.");
             File f = new File(USER_WINDOWS_CONFIG_FILE);
             if (f.exists() && f.isFile()) {
                 f.delete();
@@ -180,11 +223,11 @@ public class WindowsConfigurationManager {
 
         Element root = doc.getDocumentElement();
         Element win = createNode(root, "Window", new Object[] {"uuid", window.getUUID(),
-                                                               "x", (int) window.getLocation().getX(),
-                                                               "y", (int) window.getLocation().getY(),
-                                                               "width", (int) window.getSize().getWidth(),
-                                                               "height", (int) window.getSize().getHeight()
-            });
+                                 "x", (int) window.getLocation().getX(),
+                                 "y", (int) window.getLocation().getY(),
+                                 "width", (int) window.getSize().getWidth(),
+                                 "height", (int) window.getSize().getHeight()
+                                                              });
         LayoutNode layoutNode = window.getDockingPort().exportLayout();
         LayoutNodeSerializer serializer = new LayoutNodeSerializer();
         win.appendChild(serializer.serialize(doc, layoutNode));
@@ -333,37 +376,37 @@ public class WindowsConfigurationManager {
 
             if (requestFocus) {
                 SwingUtilities.invokeLater(new Runnable() {
-                        @Override
-                        public void run() {
-                            final Thread t = new Thread(new Runnable() {
-                                    @Override
-                                    public void run() {
-                                        synchronized (currentlyRestored) {
-                                            while (currentlyRestored.size() > 0) {
-                                                try {
-                                                    currentlyRestored.wait();
-                                                } catch (InterruptedException e) {
-                                                    e.printStackTrace();
-                                                }
-                                            }
-                                        }
-
-                                        // Be sure that te main tab or one of its subcomponent
-                                        // will have the focus on start-up
-                                        Component owner = null;
-                                        while (owner == null && !mainTab.isAncestorOf(owner)) {
-                                            mainTab.requestFocus();
-                                            Thread.yield();
-
-                                            owner = window.getFocusOwner();
+                    @Override
+                    public void run() {
+                        final Thread t = new Thread(new Runnable() {
+                            @Override
+                            public void run() {
+                                synchronized (currentlyRestored) {
+                                    while (currentlyRestored.size() > 0) {
+                                        try {
+                                            currentlyRestored.wait();
+                                        } catch (InterruptedException e) {
+                                            e.printStackTrace();
                                         }
-                                        ActiveDockableTracker.requestDockableActivation(mainTab);
-                                        window.toFront();
                                     }
-                                });
-                            t.start();
-                        }
-                    });
+                                }
+
+                                // Be sure that te main tab or one of its subcomponent
+                                // will have the focus on start-up
+                                Component owner = null;
+                                while (owner == null && !mainTab.isAncestorOf(owner)) {
+                                    mainTab.requestFocus();
+                                    Thread.yield();
+
+                                    owner = window.getFocusOwner();
+                                }
+                                ActiveDockableTracker.requestDockableActivation(mainTab);
+                                window.toFront();
+                            }
+                        });
+                        t.start();
+                    }
+                });
             }
         }
 
@@ -812,7 +855,7 @@ public class WindowsConfigurationManager {
                                             "factory", factory.getClassName(uuid),
                                             "width", (int) dim.getWidth(),
                                             "height", (int) dim.getHeight()
-            });
+                                           });
         writeDocument();
     }
 
diff --git a/scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/Image.java b/scilab/modules/preferences/src/java/org/scilab/modules/preferences/Component/Image.java
new file mode 100644 (file)
index 0000000..946b59c
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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.preferences.Component;
+
+import java.awt.BorderLayout;
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+
+import org.w3c.dom.Node;
+
+import org.scilab.modules.preferences.XComponent;
+import org.scilab.modules.preferences.XConfigManager;
+
+/**
+ * Implementation of Image compliant with extended management.
+ *
+ * @author Calixte DENIZET
+ *
+ */
+public class Image extends Panel implements XComponent {
+
+    /** Universal identifier for serialization.
+     *
+     */
+    private static final long serialVersionUID = 6183280976436648612L;
+
+    private JLabel label;
+    private String url;
+
+    /** Define the set of actuators.
+    *
+    * @return array of actuator names.
+    */
+    public String[] actuators() {
+        return new String[] {"url"};
+    }
+
+    /** Constructor.
+    *
+    * @param peer : associated view DOM node.
+    */
+    public Image(final Node peer) {
+        super(peer);
+        label = new JLabel();
+        label.setHorizontalAlignment(JLabel.CENTER);
+        setLayout(new BorderLayout());
+        add(label, BorderLayout.CENTER);
+        setVisible(true);
+        refresh(peer);
+    }
+
+    /** Refresh the component by the use of actuators.
+    *
+    * @param peer the corresponding view DOM node
+    */
+    public void refresh(final Node peer) {
+        String url = XConfigManager.getAttribute(peer, "url");
+
+        if (!url.equals(url())) {
+            url(url);
+        }
+    }
+
+    public String url() {
+        return this.url;
+    }
+
+    public void url(String url) {
+        if (!url.equals(this.url)) {
+            this.url = url.replace("$SCI", System.getenv("SCI"));
+            try {
+                URL myurl = new URL(this.url);
+                label.setIcon(new ImageIcon(myurl));
+            } catch (Exception e) {
+                System.err.println(e);
+            }
+        }
+    }
+
+    /** Developer serialization method.
+    *
+    * @return equivalent signature.
+    */
+    public final String toString() {
+        return "Image url: " + url();
+    }
+}