diff options
author | Shashank | 2017-05-29 12:40:26 +0530 |
---|---|---|
committer | Shashank | 2017-05-29 12:40:26 +0530 |
commit | 0345245e860375a32c9a437c4a9d9cae807134e9 (patch) | |
tree | ad51ecbfa7bcd3cc5f09834f1bb8c08feaa526a4 /modules/preferences/src | |
download | scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.gz scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.bz2 scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.zip |
CMSCOPE changed
Diffstat (limited to 'modules/preferences/src')
75 files changed, 11305 insertions, 0 deletions
diff --git a/modules/preferences/src/c/.deps/.dirstamp b/modules/preferences/src/c/.deps/.dirstamp new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/modules/preferences/src/c/.deps/.dirstamp diff --git a/modules/preferences/src/c/.deps/libscipreferences_algo_la-getScilabPreference.Plo b/modules/preferences/src/c/.deps/libscipreferences_algo_la-getScilabPreference.Plo new file mode 100755 index 000000000..ee32ccc9e --- /dev/null +++ b/modules/preferences/src/c/.deps/libscipreferences_algo_la-getScilabPreference.Plo @@ -0,0 +1,262 @@ +src/c/libscipreferences_algo_la-getScilabPreference.lo: \ + src/c/getScilabPreference.c /usr/include/stdc-predef.h \ + /usr/include/stdlib.h /usr/include/features.h \ + /usr/include/x86_64-linux-gnu/sys/cdefs.h \ + /usr/include/x86_64-linux-gnu/bits/wordsize.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \ + /usr/include/x86_64-linux-gnu/bits/waitflags.h \ + /usr/include/x86_64-linux-gnu/bits/waitstatus.h /usr/include/endian.h \ + /usr/include/x86_64-linux-gnu/bits/endian.h \ + /usr/include/x86_64-linux-gnu/bits/byteswap.h \ + /usr/include/x86_64-linux-gnu/bits/types.h \ + /usr/include/x86_64-linux-gnu/bits/typesizes.h \ + /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \ + /usr/include/x86_64-linux-gnu/sys/types.h /usr/include/time.h \ + /usr/include/x86_64-linux-gnu/sys/select.h \ + /usr/include/x86_64-linux-gnu/bits/select.h \ + /usr/include/x86_64-linux-gnu/bits/sigset.h \ + /usr/include/x86_64-linux-gnu/bits/time.h \ + /usr/include/x86_64-linux-gnu/bits/select2.h \ + /usr/include/x86_64-linux-gnu/sys/sysmacros.h \ + /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xpath.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlversion.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlexports.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlerror.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/parser.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/tree.h \ + /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \ + /usr/include/wchar.h /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \ + /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \ + /usr/include/x86_64-linux-gnu/bits/stdio.h \ + /usr/include/x86_64-linux-gnu/bits/stdio2.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h \ + /usr/include/limits.h /usr/include/x86_64-linux-gnu/bits/posix1_lim.h \ + /usr/include/x86_64-linux-gnu/bits/local_lim.h \ + /usr/include/linux/limits.h \ + /usr/include/x86_64-linux-gnu/bits/posix2_lim.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlstring.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlregexp.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/dict.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/hash.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/valid.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/list.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlautomata.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/entities.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/encoding.h \ + /usr/include/iconv.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlIO.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/globals.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/SAX.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xlink.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/SAX2.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlmemory.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/threads.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlreader.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/relaxng.h \ + /home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlschemas.h \ + includes/getScilabPreference.h includes/dynlib_preferences_scilab.h \ + ../../modules/core/includes/GetXmlFileEncoding.h /usr/include/string.h \ + /usr/include/xlocale.h /usr/include/x86_64-linux-gnu/bits/string.h \ + /usr/include/x86_64-linux-gnu/bits/string2.h \ + /usr/include/x86_64-linux-gnu/bits/string3.h \ + ../../modules/core/includes/MALLOC.h \ + ../../modules/core/includes/sci_mem_alloc.h \ + ../../modules/fileio/includes/FileExist.h \ + /usr/include/x86_64-linux-gnu/bits/wchar.h \ + /usr/include/x86_64-linux-gnu/bits/wchar2.h \ + ../../modules/fileio/includes/dynlib_fileio.h \ + ../../modules/core/includes/BOOL.h \ + ../../modules/string/includes/stricmp.h \ + ../../modules/fileio/includes/getshortpathname.h \ + ../../modules/core/includes/machine.h \ + ../../modules/core/includes/SCIHOME.h ../../modules/core/includes/BOOL.h + +/usr/include/stdc-predef.h: + +/usr/include/stdlib.h: + +/usr/include/features.h: + +/usr/include/x86_64-linux-gnu/sys/cdefs.h: + +/usr/include/x86_64-linux-gnu/bits/wordsize.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs-64.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h: + +/usr/include/x86_64-linux-gnu/bits/waitflags.h: + +/usr/include/x86_64-linux-gnu/bits/waitstatus.h: + +/usr/include/endian.h: + +/usr/include/x86_64-linux-gnu/bits/endian.h: + +/usr/include/x86_64-linux-gnu/bits/byteswap.h: + +/usr/include/x86_64-linux-gnu/bits/types.h: + +/usr/include/x86_64-linux-gnu/bits/typesizes.h: + +/usr/include/x86_64-linux-gnu/bits/byteswap-16.h: + +/usr/include/x86_64-linux-gnu/sys/types.h: + +/usr/include/time.h: + +/usr/include/x86_64-linux-gnu/sys/select.h: + +/usr/include/x86_64-linux-gnu/bits/select.h: + +/usr/include/x86_64-linux-gnu/bits/sigset.h: + +/usr/include/x86_64-linux-gnu/bits/time.h: + +/usr/include/x86_64-linux-gnu/bits/select2.h: + +/usr/include/x86_64-linux-gnu/sys/sysmacros.h: + +/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h: + +/usr/include/alloca.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xpath.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlversion.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlexports.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlerror.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/parser.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/tree.h: + +/usr/include/stdio.h: + +/usr/include/libio.h: + +/usr/include/_G_config.h: + +/usr/include/wchar.h: + +/usr/include/x86_64-linux-gnu/bits/stdio_lim.h: + +/usr/include/x86_64-linux-gnu/bits/sys_errlist.h: + +/usr/include/x86_64-linux-gnu/bits/stdio.h: + +/usr/include/x86_64-linux-gnu/bits/stdio2.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h: + +/usr/include/limits.h: + +/usr/include/x86_64-linux-gnu/bits/posix1_lim.h: + +/usr/include/x86_64-linux-gnu/bits/local_lim.h: + +/usr/include/linux/limits.h: + +/usr/include/x86_64-linux-gnu/bits/posix2_lim.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlstring.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlregexp.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/dict.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/hash.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/valid.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/list.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlautomata.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/entities.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/encoding.h: + +/usr/include/iconv.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlIO.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/globals.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/SAX.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xlink.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/SAX2.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlmemory.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/threads.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlreader.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/relaxng.h: + +/home/shashank/scilab-master_5.5.2/usr/include/libxml2/libxml/xmlschemas.h: + +includes/getScilabPreference.h: + +includes/dynlib_preferences_scilab.h: + +../../modules/core/includes/GetXmlFileEncoding.h: + +/usr/include/string.h: + +/usr/include/xlocale.h: + +/usr/include/x86_64-linux-gnu/bits/string.h: + +/usr/include/x86_64-linux-gnu/bits/string2.h: + +/usr/include/x86_64-linux-gnu/bits/string3.h: + +../../modules/core/includes/MALLOC.h: + +../../modules/core/includes/sci_mem_alloc.h: + +../../modules/fileio/includes/FileExist.h: + +/usr/include/x86_64-linux-gnu/bits/wchar.h: + +/usr/include/x86_64-linux-gnu/bits/wchar2.h: + +../../modules/fileio/includes/dynlib_fileio.h: + +../../modules/core/includes/BOOL.h: + +../../modules/string/includes/stricmp.h: + +../../modules/fileio/includes/getshortpathname.h: + +../../modules/core/includes/machine.h: + +../../modules/core/includes/SCIHOME.h: + +../../modules/core/includes/BOOL.h: diff --git a/modules/preferences/src/c/.dirstamp b/modules/preferences/src/c/.dirstamp new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/modules/preferences/src/c/.dirstamp diff --git a/modules/preferences/src/c/.libs/libscipreferences_algo_la-getScilabPreference.o b/modules/preferences/src/c/.libs/libscipreferences_algo_la-getScilabPreference.o Binary files differnew file mode 100755 index 000000000..19092a6e9 --- /dev/null +++ b/modules/preferences/src/c/.libs/libscipreferences_algo_la-getScilabPreference.o diff --git a/modules/preferences/src/c/DllmainPreferences.c b/modules/preferences/src/c/DllmainPreferences.c new file mode 100755 index 000000000..5010db488 --- /dev/null +++ b/modules/preferences/src/c/DllmainPreferences.c @@ -0,0 +1,34 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2009 - DIGITEO - Allan CORNET + * + * 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.1-en.txt + * + */ + +#include <windows.h> +/*--------------------------------------------------------------------------*/ +#pragma comment(lib,"../../../../bin/libintl.lib") +#pragma comment(lib, "../../../../bin/libxml2.lib") +/*--------------------------------------------------------------------------*/ +int WINAPI DllMain (HINSTANCE hInstance , DWORD reason, PVOID pvReserved) +{ + switch (reason) + { + case DLL_PROCESS_ATTACH: + break; + case DLL_PROCESS_DETACH: + break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + break; + } + return 1; +} +/*--------------------------------------------------------------------------*/ + diff --git a/modules/preferences/src/c/core_Import.def b/modules/preferences/src/c/core_Import.def new file mode 100755 index 000000000..4d6229447 --- /dev/null +++ b/modules/preferences/src/c/core_Import.def @@ -0,0 +1,11 @@ +LIBRARY core.dll + + +EXPORTS +; +callFunctionFromGateway +getScilabMode +com_ +getSCIHOME +MyHeapAlloc +MyHeapFree diff --git a/modules/preferences/src/c/getScilabPreference.c b/modules/preferences/src/c/getScilabPreference.c new file mode 100755 index 000000000..13f6a0e8f --- /dev/null +++ b/modules/preferences/src/c/getScilabPreference.c @@ -0,0 +1,426 @@ +/* + * 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.1-en.txt + * + */ + +/*--------------------------------------------------------------------------*/ +#include <stdlib.h> +#include <libxml/xpath.h> +#include <libxml/xmlreader.h> +#include "getScilabPreference.h" +#include "GetXmlFileEncoding.h" +#include "MALLOC.h" +#include "FileExist.h" +#include "stricmp.h" +#ifdef _MSC_VER +#include "strdup_windows.h" +#endif +#include "getshortpathname.h" +#include "BOOL.h" +#include "SCIHOME.h" + +#define XCONF "%s/XConfiguration.xml" + +/*--------------------------------------------------------------------------*/ +static unsigned char isInit = 0; +static ScilabPreferences scilabPref; +static char * emptyAttribute = ""; +/*--------------------------------------------------------------------------*/ +static void getPrefs(); +static char * getAttribute(xmlDocPtr doc, xmlXPathContextPtr xpathCtxt, const char * xpath); +static void initPrefs(); +static void getDocAndCtxt(xmlDocPtr * doc, xmlXPathContextPtr * xpathCtxt); +/*--------------------------------------------------------------------------*/ +const ScilabPreferences * getScilabPreferences() +{ + getPrefs(); + return &scilabPref; +} +/*--------------------------------------------------------------------------*/ +void initPrefs() +{ + scilabPref.heapSize = NULL; + scilabPref.adaptToDisplay = NULL; + scilabPref.columnsToDisplay = NULL; + scilabPref.linesToDisplay = NULL; + scilabPref.historySaveAfter = NULL; + scilabPref.historyFile = NULL; + scilabPref.historyLines = NULL; + scilabPref.historyEnable = NULL; + scilabPref.ieee = NULL; + scilabPref.format = NULL; + scilabPref.formatWidth = NULL; + scilabPref.language = NULL; + scilabPref.startup_dir_use = NULL; + scilabPref.startup_dir_default = NULL; + scilabPref.startup_dir_previous = NULL; +} +/*--------------------------------------------------------------------------*/ +void reloadScilabPreferences() +{ + clearScilabPreferences(); + getPrefs(); +} +/*--------------------------------------------------------------------------*/ +void clearScilabPreferences() +{ + if (isInit == 1) + { + if (scilabPref.heapSize) + { + FREE((void*)scilabPref.heapSize); + } + if (scilabPref.adaptToDisplay) + { + FREE((void*)scilabPref.adaptToDisplay); + } + if (scilabPref.columnsToDisplay) + { + FREE((void*)scilabPref.columnsToDisplay); + } + if (scilabPref.linesToDisplay) + { + FREE((void*)scilabPref.linesToDisplay); + } + if (scilabPref.historySaveAfter) + { + FREE((void*)scilabPref.historySaveAfter); + } + if (scilabPref.historyFile) + { + FREE((void*)scilabPref.historyFile); + } + if (scilabPref.historyLines) + { + FREE((void*)scilabPref.historyLines); + } + if (scilabPref.historyEnable) + { + FREE((void*)scilabPref.historyEnable); + } + if (scilabPref.ieee) + { + FREE((void*)scilabPref.ieee); + } + if (scilabPref.format) + { + FREE((void*)scilabPref.format); + } + if (scilabPref.formatWidth) + { + FREE((void*)scilabPref.formatWidth); + } + if (scilabPref.language) + { + FREE((void*)scilabPref.language); + } + if (scilabPref.startup_dir_use) + { + FREE((void*)scilabPref.startup_dir_use); + } + if (scilabPref.startup_dir_default) + { + FREE((void*)scilabPref.startup_dir_default); + } + if (scilabPref.startup_dir_previous) + { + FREE((void*)scilabPref.startup_dir_previous); + } + initPrefs(); + } + isInit = 0; +} +/*--------------------------------------------------------------------------*/ +void getPrefs() +{ + if (!isInit) + { + xmlDocPtr doc = NULL; + xmlXPathContextPtr xpathCtxt = NULL; + + initPrefs(); + + getDocAndCtxt(&doc, &xpathCtxt); + if (doc == NULL) + { + return; + } + + scilabPref.heapSize = strdup(getAttribute(doc, xpathCtxt, HEAPSIZE_XPATH)); + scilabPref.adaptToDisplay = strdup(getAttribute(doc, xpathCtxt, ADAPTTODISPLAY_XPATH)); + scilabPref.columnsToDisplay = strdup(getAttribute(doc, xpathCtxt, COLUMNSTODISPLAY_XPATH)); + scilabPref.linesToDisplay = strdup(getAttribute(doc, xpathCtxt, LINESTODISPLAY_XPATH)); + scilabPref.historySaveAfter = strdup(getAttribute(doc, xpathCtxt, HISTORYSAVEAFTER_XPATH)); + scilabPref.historyFile = strdup(getAttribute(doc, xpathCtxt, HISTORYFILE_XPATH)); + scilabPref.historyLines = strdup(getAttribute(doc, xpathCtxt, HISTORYLINES_XPATH)); + scilabPref.historyEnable = strdup(getAttribute(doc, xpathCtxt, HISTORYENABLE_XPATH)); + scilabPref.ieee = strdup(getAttribute(doc, xpathCtxt, IEEE_XPATH)); + scilabPref.format = strdup(getAttribute(doc, xpathCtxt, FORMAT_XPATH)); + scilabPref.formatWidth = strdup(getAttribute(doc, xpathCtxt, FORMATWIDTH_XPATH)); + scilabPref.language = strdup(getAttribute(doc, xpathCtxt, LANGUAGE_XPATH)); + scilabPref.startup_dir_use = strdup(getAttribute(doc, xpathCtxt, STARTUP_DIR_USE_XPATH)); + scilabPref.startup_dir_default = strdup(getAttribute(doc, xpathCtxt, STARTUP_DIR_DEFAULT_XPATH)); + scilabPref.startup_dir_previous = strdup(getAttribute(doc, xpathCtxt, STARTUP_DIR_PREVIOUS_XPATH)); + + xmlXPathFreeContext(xpathCtxt); + xmlFreeDoc(doc); + + isInit = 1; + } +} +/*--------------------------------------------------------------------------*/ +char * getAttribute(xmlDocPtr doc, xmlXPathContextPtr xpathCtxt, const char * xpath) +{ + char * value = emptyAttribute; + xmlXPathObjectPtr xpathObj = xmlXPathEval((const xmlChar*)xpath, xpathCtxt); + if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeMax) + { + value = (char *)((xmlAttrPtr)xpathObj->nodesetval->nodeTab[0])->children->content; + } + + if (xpathObj) + { + xmlXPathFreeObject(xpathObj); + } + + return value; +} +/*--------------------------------------------------------------------------*/ +void getDocAndCtxt(xmlDocPtr * doc, xmlXPathContextPtr * xpathCtxt) +{ + char * SCIHOME = NULL; + char * path = NULL; + BOOL bConvert = FALSE; + char * shortfilename_xml_conf = NULL; + char * ret = NULL; + *doc = NULL; + *xpathCtxt = NULL; + + SCIHOME = getSCIHOME(); + path = (char *)MALLOC(strlen(SCIHOME) + strlen(XCONF)); + + sprintf(path, XCONF, SCIHOME); + FREE(SCIHOME); + + if (FileExist(path)) + { + shortfilename_xml_conf = getshortpathname(path, &bConvert); + if (shortfilename_xml_conf) + { + *doc = xmlParseFile(shortfilename_xml_conf); + FREE(shortfilename_xml_conf); + shortfilename_xml_conf = NULL; + } + } + + FREE(path); + path = NULL; + + if (*doc == NULL) + { + *xpathCtxt = NULL; + return; + } + + if (stricmp((*doc)->encoding, "utf-8")) + { + xmlFreeDoc(*doc); + *doc = NULL; + *xpathCtxt = NULL; + return; + } + + *xpathCtxt = xmlXPathNewContext(*doc); + if (*xpathCtxt == NULL) + { + xmlFreeDoc(*doc); + *doc = NULL; + } +} +/*--------------------------------------------------------------------------*/ +char * getPrefAttributeValue(const char * xpath, const char * attribute) +{ + xmlDocPtr doc = NULL; + xmlXPathContextPtr xpathCtxt = NULL; + char * ret = NULL; + unsigned int xlen = 0; + unsigned int alen = 0; + char * query = NULL; + + if (!xpath || !attribute) + { + return NULL; + } + + query = (char *)MALLOC((xlen + alen + 2 + 1) * sizeof(char)); + if (!query) + { + return NULL; + } + + xlen = (unsigned int) strlen(xpath); + alen = (unsigned int) strlen(attribute); + + getDocAndCtxt(&doc, &xpathCtxt); + if (doc == NULL) + { + FREE(query); + return NULL; + } + + sprintf(query, "%s/@%s", xpath, attribute); + query[xlen + alen + 2] = '\0'; + + ret = strdup(getAttribute(doc, xpathCtxt, (const xmlChar*)query)); + FREE(query); + + xmlXPathFreeContext(xpathCtxt); + xmlFreeDoc(doc); + + return ret; +} +/*--------------------------------------------------------------------------*/ +char ** getPrefAttributesValues(const char * xpath, const char ** attributes, const unsigned int attrLen) +{ + xmlDocPtr doc = NULL; + xmlXPathContextPtr xpathCtxt = NULL; + xmlXPathObjectPtr xpathObj = NULL; + char ** ret = NULL; + + if (!xpath || !attributes || !attrLen) + { + return NULL; + } + + getDocAndCtxt(&doc, &xpathCtxt); + if (doc == NULL || xpathCtxt == NULL) + { + return NULL; + } + + xpathObj = xmlXPathEval((const xmlChar*)xpath, xpathCtxt); + if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeMax) + { + unsigned int i; + xmlNode * node = (xmlNode*)xpathObj->nodesetval->nodeTab[0]; + ret = (char**)MALLOC(sizeof(char*) * attrLen); + if (!ret) + { + xmlXPathFreeObject(xpathObj); + xmlXPathFreeContext(xpathCtxt); + xmlFreeDoc(doc); + return NULL; + } + + for (i = 0; i < attrLen; i++) + { + xmlAttr * attrs = xmlHasProp(node, (const xmlChar *)attributes[i]); + if (attrs) + { + ret[i] = strdup((const char *)attrs->children->content); + } + + if (!attrs || !ret[i]) + { + unsigned int j; + for (j = 0; j < i; j++) + { + free(ret[j]); + } + FREE(ret); + ret = NULL; + break; + } + } + } + + if (xpathObj) + { + xmlXPathFreeObject(xpathObj); + } + + xmlXPathFreeContext(xpathCtxt); + xmlFreeDoc(doc); + + return ret; +} +/*--------------------------------------------------------------------------*/ +void setPrefAttributesValues(const char * xpath, const char ** kv, const unsigned int kvLen) +{ + xmlDocPtr doc = NULL; + xmlXPathContextPtr xpathCtxt = NULL; + xmlXPathObjectPtr xpathObj = NULL; + char * SCIHOME = NULL; + char * path = NULL; + BOOL bConvert = FALSE; + char * shortfilename_xml_conf = NULL; + + if (!xpath || !kv || !kvLen) + { + return; + } + + getDocAndCtxt(&doc, &xpathCtxt); + if (doc == NULL) + { + return; + } + + xpathObj = xmlXPathEval((const xmlChar*)xpath, xpathCtxt); + if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeMax) + { + int i; + xmlNode * node = (xmlNode*)xpathObj->nodesetval->nodeTab[0]; + for (i = 0; i < (int)kvLen / 2; i++) + { + xmlAttr * attrs = xmlHasProp(node, (const xmlChar *)kv[2 * i]); + if (attrs) + { + attrs->children->content = xmlStrdup((const xmlChar *)kv[2 * i + 1]); + } + else + { + break; + } + } + } + + if (xpathObj) + { + xmlXPathFreeObject(xpathObj); + } + + xmlXPathFreeContext(xpathCtxt); + + // Save + xmlThrDefIndentTreeOutput(1); + + SCIHOME = getSCIHOME(); + path = (char *)MALLOC(strlen(SCIHOME) + strlen(XCONF)); + + sprintf(path, XCONF, SCIHOME); + FREE(SCIHOME); + + if (FileExist(path)) + { + shortfilename_xml_conf = getshortpathname(path, &bConvert); + if (shortfilename_xml_conf) + { + xmlSaveFormatFile(shortfilename_xml_conf, doc, 2); + FREE(shortfilename_xml_conf); + shortfilename_xml_conf = NULL; + } + } + + FREE(path); + path = NULL; + + xmlFreeDoc(doc); +} diff --git a/modules/preferences/src/c/libscipreferences_algo_la-getScilabPreference.lo b/modules/preferences/src/c/libscipreferences_algo_la-getScilabPreference.lo new file mode 100755 index 000000000..8e33b0c04 --- /dev/null +++ b/modules/preferences/src/c/libscipreferences_algo_la-getScilabPreference.lo @@ -0,0 +1,12 @@ +# src/c/libscipreferences_algo_la-getScilabPreference.lo - a libtool object file +# Generated by libtool (GNU libtool) 2.4.2 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/libscipreferences_algo_la-getScilabPreference.o' + +# Name of the non-PIC object +non_pic_object=none + diff --git a/modules/preferences/src/c/preferences.rc b/modules/preferences/src/c/preferences.rc new file mode 100755 index 000000000..c17ef1b65 --- /dev/null +++ b/modules/preferences/src/c/preferences.rc @@ -0,0 +1,96 @@ +// Microsoft Visual C++ generated resource script. +// + + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +//#include "afxres.h" +#define APSTUDIO_HIDDEN_SYMBOLS +#include "windows.h" +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// French (France) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA) +#ifdef _WIN32 +LANGUAGE LANG_FRENCH, SUBLANG_FRENCH +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 5,5,2,0 + PRODUCTVERSION 5,5,2,0 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040c04b0" + BEGIN + VALUE "FileDescription", "preferences module" + VALUE "FileVersion", "5, 5, 2, 0" + VALUE "InternalName", "preferences module" + VALUE "LegalCopyright", "Copyright (C) 2011" + VALUE "OriginalFilename", "preferences.dll" + VALUE "ProductName", "preferences module" + VALUE "ProductVersion", "5, 5, 2, 0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x40c, 1200 + END +END + +#endif // French (France) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/modules/preferences/src/c/preferences.vcxproj b/modules/preferences/src/c/preferences.vcxproj new file mode 100755 index 000000000..24351f30d --- /dev/null +++ b/modules/preferences/src/c/preferences.vcxproj @@ -0,0 +1,292 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{7B893E9F-D032-44DE-9B71-197A29C4989B}</ProjectGuid> + <RootNamespace>preferences</RootNamespace> + <Keyword>Win32Proj</Keyword> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <CharacterSet>MultiByte</CharacterSet> + <WholeProgramOptimization>false</WholeProgramOptimization> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <CharacterSet>MultiByte</CharacterSet> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <CharacterSet>MultiByte</CharacterSet> + <WholeProgramOptimization>false</WholeProgramOptimization> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <CharacterSet>MultiByte</CharacterSet> + <PlatformToolset>v110</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup> + <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)bin\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)$(Configuration)\</IntDir> + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)bin\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)$(Configuration)\</IntDir> + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)bin\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)$(Configuration)\</IntDir> + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental> + <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)bin\</OutDir> + <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir)$(Configuration)\</IntDir> + <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <AdditionalOptions>%(AdditionalOptions)</AdditionalOptions> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>../../includes;.;../jni;../cpp;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../../../libs/intl;../../../api_scilab/includes;../../../core/includes;../../../localization/includes;../../../jvm/includes;../../../fileio/includes;../../../output_stream/includes;../../../commons/src/jni;../../../../libs/libxml2;../../../string/includes;../../../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;_DEBUG;_WINDOWS;_USRDLL;PREFERENCES_SCILAB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <MinimalRebuild>true</MinimalRebuild> + <BasicRuntimeChecks>Default</BasicRuntimeChecks> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <DisableSpecificWarnings>4251</DisableSpecificWarnings> + </ClCompile> + <PreLinkEvent> + <Message>Make dependencies</Message> + <Command>lib /DEF:"$(ProjectDir)core_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core.lib" 1>NUL 2>NUL +</Command> + </PreLinkEvent> + <Link> + <AdditionalDependencies>core.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile> + <ModuleDefinitionFile> + </ModuleDefinitionFile> + <GenerateDebugInformation>true</GenerateDebugInformation> + <SubSystem>Windows</SubSystem> + <RandomizedBaseAddress>false</RandomizedBaseAddress> + <DataExecutionPrevention> + </DataExecutionPrevention> + <ImportLibrary>$(SolutionDir)bin\$(ProjectName).lib</ImportLibrary> + <TargetMachine>MachineX86</TargetMachine> + <CLRUnmanagedCodeCheck>true</CLRUnmanagedCodeCheck> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Midl> + <TargetEnvironment>X64</TargetEnvironment> + </Midl> + <ClCompile> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>../../includes;.;../jni;../cpp;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../../../libs/intl;../../../api_scilab/includes;../../../core/includes;../../../localization/includes;../../../jvm/includes;../../../fileio/includes;../../../output_stream/includes;../../../commons/src/jni;../../../../libs/libxml2;../../../string/includes;../../../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;_DEBUG;_WINDOWS;_USRDLL;PREFERENCES_SCILAB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <MinimalRebuild>true</MinimalRebuild> + <BasicRuntimeChecks>Default</BasicRuntimeChecks> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <DisableSpecificWarnings>4251</DisableSpecificWarnings> + </ClCompile> + <PreLinkEvent> + <Message>Make dependencies</Message> + <Command>lib /DEF:"$(ProjectDir)core_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core.lib" 1>NUL 2>NUL +</Command> + </PreLinkEvent> + <Link> + <AdditionalDependencies>core.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile> + <ModuleDefinitionFile> + </ModuleDefinitionFile> + <GenerateDebugInformation>true</GenerateDebugInformation> + <SubSystem>Windows</SubSystem> + <RandomizedBaseAddress>false</RandomizedBaseAddress> + <DataExecutionPrevention> + </DataExecutionPrevention> + <ImportLibrary>$(SolutionDir)bin\$(ProjectName).lib</ImportLibrary> + <TargetMachine>MachineX64</TargetMachine> + <CLRUnmanagedCodeCheck>true</CLRUnmanagedCodeCheck> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <AdditionalOptions>%(AdditionalOptions)</AdditionalOptions> + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> + <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> + <WholeProgramOptimization>false</WholeProgramOptimization> + <AdditionalIncludeDirectories>../../includes;.;../jni;../cpp;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../../../libs/intl;../../../api_scilab/includes;../../../core/includes;../../../localization/includes;../../../jvm/includes;../../../fileio/includes;../../../output_stream/includes;../../../commons/src/jni;../../../../libs/libxml2;../../../string/includes;../../../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;NDEBUG;_WINDOWS;_USRDLL;PREFERENCES_SCILAB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <StringPooling>true</StringPooling> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <DisableSpecificWarnings>4251</DisableSpecificWarnings> + </ClCompile> + <PreLinkEvent> + <Message>Make dependencies</Message> + <Command>lib /DEF:"$(ProjectDir)core_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core.lib" 1>NUL 2>NUL +</Command> + </PreLinkEvent> + <Link> + <AdditionalDependencies>core.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile> + <ModuleDefinitionFile> + </ModuleDefinitionFile> + <GenerateDebugInformation>false</GenerateDebugInformation> + <SubSystem>Windows</SubSystem> + <OptimizeReferences>true</OptimizeReferences> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <LinkTimeCodeGeneration> + </LinkTimeCodeGeneration> + <RandomizedBaseAddress>false</RandomizedBaseAddress> + <DataExecutionPrevention> + </DataExecutionPrevention> + <ImportLibrary>$(SolutionDir)bin\$(ProjectName).lib</ImportLibrary> + <TargetMachine>MachineX86</TargetMachine> + <CLRUnmanagedCodeCheck>true</CLRUnmanagedCodeCheck> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Midl> + <TargetEnvironment>X64</TargetEnvironment> + </Midl> + <ClCompile> + <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> + <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> + <WholeProgramOptimization>false</WholeProgramOptimization> + <AdditionalIncludeDirectories>../../includes;.;../jni;../cpp;../../../../java/jdk/include;../../../../java/jdk/include/win32;../../../../libs/intl;../../../api_scilab/includes;../../../core/includes;../../../localization/includes;../../../jvm/includes;../../../fileio/includes;../../../output_stream/includes;../../../commons/src/jni;../../../../libs/libxml2;../../../string/includes;../../../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;NDEBUG;_WINDOWS;_USRDLL;PREFERENCES_SCILAB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <StringPooling>true</StringPooling> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <DisableSpecificWarnings>4251</DisableSpecificWarnings> + </ClCompile> + <PreLinkEvent> + <Message>Make dependencies</Message> + <Command>lib /DEF:"$(ProjectDir)core_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core.lib" 1>NUL 2>NUL +</Command> + </PreLinkEvent> + <Link> + <AdditionalDependencies>core.lib;%(AdditionalDependencies)</AdditionalDependencies> + <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile> + <ModuleDefinitionFile> + </ModuleDefinitionFile> + <GenerateDebugInformation>false</GenerateDebugInformation> + <SubSystem>Windows</SubSystem> + <OptimizeReferences>true</OptimizeReferences> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <LinkTimeCodeGeneration> + </LinkTimeCodeGeneration> + <RandomizedBaseAddress>false</RandomizedBaseAddress> + <DataExecutionPrevention> + </DataExecutionPrevention> + <ImportLibrary>$(SolutionDir)bin\$(ProjectName).lib</ImportLibrary> + <TargetMachine>MachineX64</TargetMachine> + <CLRUnmanagedCodeCheck>true</CLRUnmanagedCodeCheck> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <None Include="core_import.def" /> + <None Include="..\..\Makefile.am" /> + <None Include="..\..\preferences.iss" /> + <None Include="..\..\sci_gateway\preferences_gateway.xml" /> + </ItemGroup> + <ItemGroup> + <ResourceCompile Include="preferences.rc" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\api_scilab\api_scilab.vcxproj"> + <Project>{43c5bab1-1dca-4743-a183-77e0d42fe7d0}</Project> + <ReferenceOutputAssembly>false</ReferenceOutputAssembly> + </ProjectReference> + <ProjectReference Include="..\..\..\commons\src\c\commons.vcxproj"> + <Project>{eca09a1e-6d12-4a47-92e1-a671c181df77}</Project> + </ProjectReference> + <ProjectReference Include="..\..\..\fileio\fileio.vcxproj"> + <Project>{4fc72d4a-80ee-4b1a-8724-0201c1a35621}</Project> + </ProjectReference> + <ProjectReference Include="..\..\..\jvm\libjvm.vcxproj"> + <Project>{8ba2dda8-bd04-4d4d-8ee6-6caa955f7470}</Project> + <ReferenceOutputAssembly>false</ReferenceOutputAssembly> + </ProjectReference> + <ProjectReference Include="..\..\..\localization\src\localization.vcxproj"> + <Project>{ecffeb0c-1eda-45ee-9a10-b18143852e17}</Project> + <ReferenceOutputAssembly>false</ReferenceOutputAssembly> + </ProjectReference> + <ProjectReference Include="..\..\..\output_stream\src\c\output_stream.vcxproj"> + <Project>{a5911cd7-f8e8-440c-a23e-4843a0636f3a}</Project> + <ReferenceOutputAssembly>false</ReferenceOutputAssembly> + </ProjectReference> + <ProjectReference Include="..\..\..\windows_tools\src\c\scilab_windows\scilab_windows.vcxproj"> + <Project>{8028f371-6a94-4a26-8804-6e7f05f1d1aa}</Project> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <ClCompile Include="..\..\sci_gateway\cpp\sci_addModulePreferences.cpp" /> + <ClCompile Include="..\..\sci_gateway\cpp\sci_preferences.cpp" /> + <ClCompile Include="..\..\sci_gateway\cpp\sci_removeModulePreferences.cpp" /> + <ClCompile Include="..\..\sci_gateway\c\gw_preferences.c" /> + <ClCompile Include="..\jni\ScilabPreferences.cpp" /> + <ClCompile Include="DllmainPreferences.c" /> + <ClCompile Include="getScilabPreference.c" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\..\includes\dynlib_preferences_scilab.h" /> + <ClInclude Include="..\..\includes\getScilabPreference.h" /> + <ClInclude Include="..\..\includes\gw_preferences.h" /> + <ClInclude Include="..\jni\ScilabPreferences.hxx" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/modules/preferences/src/c/preferences.vcxproj.filters b/modules/preferences/src/c/preferences.vcxproj.filters new file mode 100755 index 000000000..6968f7503 --- /dev/null +++ b/modules/preferences/src/c/preferences.vcxproj.filters @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{03fbdde8-2541-40ee-b83f-7bda6ed23378}</UniqueIdentifier> + <Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{55490fa8-9302-4001-9210-cbc2aa6747ec}</UniqueIdentifier> + <Extensions>h;hpp;hxx;hm;inl</Extensions> + </Filter> + <Filter Include="localization"> + <UniqueIdentifier>{7ed96ca6-802f-40a5-910e-a6881cf98c3d}</UniqueIdentifier> + </Filter> + <Filter Include="Libraries Dependencies"> + <UniqueIdentifier>{a56ef58c-a5d4-410e-b230-a14d884ad982}</UniqueIdentifier> + </Filter> + <Filter Include="Libraries Dependencies\Imports"> + <UniqueIdentifier>{e60d124f-f2a9-42ae-9bd7-2d37894651db}</UniqueIdentifier> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{abf739f5-063b-407b-a7a1-8b18fdebd6ca}</UniqueIdentifier> + </Filter> + </ItemGroup> + <ItemGroup> + <None Include="core_import.def"> + <Filter>Libraries Dependencies\Imports</Filter> + </None> + <None Include="..\..\Makefile.am" /> + <None Include="..\..\preferences.iss" /> + <None Include="..\..\sci_gateway\preferences_gateway.xml" /> + </ItemGroup> + <ItemGroup> + <ResourceCompile Include="preferences.rc"> + <Filter>Resource Files</Filter> + </ResourceCompile> + </ItemGroup> + <ItemGroup> + <ClCompile Include="DllmainPreferences.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\jni\ScilabPreferences.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\..\sci_gateway\c\gw_preferences.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\..\sci_gateway\cpp\sci_addModulePreferences.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\..\sci_gateway\cpp\sci_removeModulePreferences.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="getScilabPreference.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\..\sci_gateway\cpp\sci_preferences.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\jni\ScilabPreferences.hxx"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\..\includes\dynlib_preferences_scilab.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\..\includes\gw_preferences.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\..\includes\getScilabPreference.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Button.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Button.java new file mode 100755 index 000000000..cce7f7ec9 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Button.java @@ -0,0 +1,108 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import javax.swing.JButton; + +import org.w3c.dom.Node; + +import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; + +/** Implementation of Button compliant with extended management. + * + * @author Pierre GRADIT + * + */ +//public class Button extends JButton implements XComponent { +public class Button extends JButton implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -3412653691044553310L; + + + private String cachedStatus = "enabled"; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {"enable", "text"}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Button(final Node peer) { + super(); + setRequestFocusEnabled(true); + setFocusable(true); + + refresh(peer); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public final void refresh(final Node peer) { + String text = XCommonManager.getAttribute(peer, "text", XCommonManager.NAV); + if (!text.equals(text())) { + text(text); + } + + String enable = XConfigManager.getAttribute(peer , "enable", "true"); + setEnabled(enable.equals("true")); + } + + /** Sensor for 'text' attribute. + * + * @return the attribute value. + */ + public final String text() { + return getText(); + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void text(final String text) { + setText(text); + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "Button"; + + if (!text().equals(XConfigManager.NAV)) { + signature += " text='" + text() + "'"; + } + + return signature; + } + + +} + + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Checkbox.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Checkbox.java new file mode 100755 index 000000000..a623692aa --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Checkbox.java @@ -0,0 +1,208 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XConfigManager; +import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox; + +import org.w3c.dom.Node; + +/** Implementation of Checkbox compliant with extended management. + * + * @author Pierre GRADIT + * + */ +public class Checkbox extends SwingScilabCheckBox implements XComponent, XChooser { + + /** Universal identifier for serialization. + * + */ + 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 = {"enable", "text", "checked", "selected-value", "unselected-value"}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Checkbox(final Node peer) { + super(); + setOpaque(false); + setRequestFocusEnabled(true); + setFocusable(true); + + refresh(peer); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public final void refresh(final Node peer) { + String text = XConfigManager.getAttribute(peer, "text"); + if (!text.equals(text())) { + text(text); + } + + 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. + */ + public final String text() { + String text = getText(); + if (text != null) { + return text; + } else { + return XConfigManager.NAV; + } + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void text(final String text) { + if (text != XConfigManager.NAV) { + setText(text); + } else { + setText(null); + } + } + + /** Sensor for 'checked' attribute. + * + * @return the attribute value. + */ + public final String checked() { + boolean state = isSelected(); + if (state) { + return "checked"; + } else { + return "unchecked"; + } + } + + /** Actuator for 'checked' attribute. + * + * @param text : the attribute value. + */ + public final void checked(final String 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. + */ + 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. + */ + public final String toString() { + String signature = "CHECKBOX"; + if (!text().equals(XConfigManager.NAV)) { + signature += " text='" + text() + "'"; + } + if (!checked().equals(XConfigManager.NAV)) { + signature += " checked='" + checked() + "'"; + } + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Color.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Color.java new file mode 100755 index 000000000..cc043499a --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Color.java @@ -0,0 +1,183 @@ +/* + * 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.1-en.txt + * + */ + +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; + +import org.scilab.modules.gui.bridge.colorchooser.SwingScilabColorChooser; +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XConfigManager; +import org.scilab.modules.preferences.XSentinel; + +/** + * Implementation of Label compliant with extended management. + * + * @author Pierre GRADIT + * @author Calixte DENIZET + */ +public class Color extends JButton implements XComponent, XChooser { + + /** + * + */ + private static final long serialVersionUID = 5598263085800128888L; + private static final int ICONDIM = 16; + + private ActionListener actionListener = null; + private SwingScilabColorChooser colorChooser; + + /** + * Define the set of actuators. + * @return array of actuator names. + */ + public final String[] actuators() { + String[] actuators = {"enable", "color"}; + return actuators; + } + + /** + * Constructor. + * @param peer : associated view DOM node. + */ + public Color(final Node peer) { + super(new Icon() { + 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()); + } + } + }); + + 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); + JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, Color.this); + colorChooser.setLocationRelativeTo(frame); + colorChooser.displayAndWait(); + if (actionListener != null) { + actionListener.actionPerformed(transmit); + } + } + }); + + setRequestFocusEnabled(true); + setFocusable(true); + + String enable = XConfigManager.getAttribute(peer , "enable", "true"); + setEnabled(enable.equals("true")); + } + + /** + * Refresh the component by the use of actuators. + * @param peer the corresponding view DOM node + */ + public final void refresh(final Node peer) { + String color = XCommonManager.getAttribute(peer , "color", "000000"); + if (!color.equals(color())) { + color(color); + } + + String enable = XConfigManager.getAttribute(peer , "enable", "true"); + setEnabled(enable.equals("true")); + } + + /** + * Sensor for 'color' attribute. + * @return the attribute value. + */ + public final String color() { + java.awt.Color color = getForeground(); + return XCommonManager.getColor(color); + } + + /** + * Actuator for 'color' attribute. + * @param text : the attribute value. + */ + public final void color(final String color) { + java.awt.Color jColor = XCommonManager.getColor(color); + setForeground(jColor); + } + + /** + * Registration of a single listener. + * @param listener + */ + public void addActionListener(ActionListener listener) { + if (listener instanceof XSentinel) { + actionListener = listener; + } else { + super.addActionListener(listener); + } + } + + /** + * External consultation + */ + public Object choose() { + java.awt.Color jColor = colorChooser.getSelectedColor(); + if (jColor != null) { + return XCommonManager.getColor(jColor); + } else { + return color(); + } + } + + /** + * Developer serialization method. + * @return equivalent signature. + */ + public final String toString() { + String signature = "Color"; + signature += " color='" + color() + "'"; + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Entry.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Entry.java new file mode 100755 index 000000000..69f71cc2f --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Entry.java @@ -0,0 +1,132 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import javax.swing.JPasswordField; + +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.checkbox.SwingScilabCheckBox; + +import org.w3c.dom.Node; + +/** Implementation of Entry compliant with extended management. + * + * @author Pierre GRADIT + * + */ +public class Entry extends JPasswordField implements XComponent, XChooser { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -7007541669965737408L; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {"enable", "text", "columns", "lines", "editable"}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Entry(final Node peer) { + super(); + refresh(peer); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public final void refresh(final Node peer) { + String text = XCommonManager.getAttribute(peer, "text"); + String columns = XCommonManager.getAttribute(peer, "columns"); + if (!text.equals(text())) { + text(text); + } + if (!columns.equals(columns())) { + columns(columns); + } + String enable = XConfigManager.getAttribute(peer, "enable", "true"); + setEnabled(enable.equals("true")); + + String passwd = XConfigManager.getAttribute(peer, "password", "false"); + if (!"true".equals(passwd)) { + setEchoChar('\0'); + } + } + + /** Sensor for 'text' attribute. + * + * @return the attribute value. + */ + public final String text() { + return new String(getPassword()); + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void columns(final String columns) { + if (! (columns.equals(XCommonManager.NAV))) { + int jColumns = Integer.parseInt(columns); + setColumns(jColumns); + } + } + + /** Sensor for 'columns' attribute. + * + * @return the attribute value. + */ + public final String columns() { + return "" + getColumns(); + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void text(final String text) { + setText(text); + } + + + /** Actual response read by the listener. + * + * @return response read by the listener. + */ + public final Object choose() { + return text(); + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "Entry"; + if (!text().equals(XCommonManager.NAV)) { + signature += " text='" + text() + "'"; + } + return signature; + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/File.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/File.java new file mode 100755 index 000000000..560214a2d --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/File.java @@ -0,0 +1,201 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import javax.swing.JTextField; + +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.colorchooser.SwingScilabColorChooser; +import org.scilab.modules.gui.filechooser.Juigetfile; + +import org.w3c.dom.Node; + +/** Implementation of Entry compliant with extended management. + * + * @author Pierre GRADIT + * + */ +public class File extends JTextField implements XComponent, XChooser, MouseListener { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -7007541669965737408L; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {"enable", "href", "desc", "mask"}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public File(final Node peer) { + super(); + refresh(peer); + addMouseListener(this); + } + + /** 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"); + String mask = XCommonManager.getAttribute(peer , "mask"); + String desc = XCommonManager.getAttribute(peer , "desc"); + + if (!href.equals(href())) { + href(href); + } + if (!mask.equals(mask())) { + mask(mask); + } + if (!desc.equals(desc())) { + desc(desc); + } + String enable = XConfigManager.getAttribute(peer , "enable", "true"); + setEnabled(enable.equals("true")); + } + + String jMask, jDesc; + + /** Sensor for 'mask' attribute. + * + * @return the attribute value. + */ + public final String mask() { + return jMask; + } + + /** Actuator for 'mask' attribute. + * + * @param mask : the attribute value. + */ + public final void mask(final String mask) { + jMask = mask; + } + + /** Sensor for 'desc' attribute. + * + * @return the attribute value. + */ + public final String desc() { + return jDesc; + } + + /** Actuator for 'desc' attribute. + * + * @param text : the attribute value. + */ + public final void desc(final String desc) { + jDesc = desc; + } + + + /** Sensor for 'href' attribute. + * + * @return the attribute value. + */ + public final String href() { + return getText(); + } + + /** Actuator for 'href' attribute. + * + * @param text : the attribute value. + */ + public final void href(final String href) { + setText(href); + } + + public void mouseClicked(final MouseEvent e) { + if (actionListener != null && isEnabled()) { + ActionEvent transmit = new ActionEvent(this, e.getID(), "File change", e.getWhen() + 1, e.getModifiers()); + actionListener.actionPerformed(transmit); + } + } + + /** Mouse listener unused callback. @param e : event*/ + public void mouseEntered(final MouseEvent e) { + } + /** Mouse listener unused callback. @param e : event*/ + public void mouseExited(final MouseEvent e) { + } + /** Mouse listener unused callback. @param e : event*/ + public void mousePressed(final MouseEvent e) { + } + /** Mouse listener unused callback. @param e : event*/ + public void mouseReleased(final MouseEvent e) { + } + + /** Actual response read by the listener. + * + * @return response read by the listener. + */ + public final Object choose() { + String mask[] = {jMask}; + String desc[] = {jDesc}; + Juigetfile.uigetfile(mask, desc); + String selection[] = Juigetfile.getSelection(); + if (selection.length > 0) { + return selection[0]; + } + return href(); + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "File"; + if (!href().equals(XCommonManager.NAV)) { + signature += " href='" + href() + "'"; + } + if (!desc().equals(XCommonManager.NAV)) { + signature += " desc='" + desc() + "'"; + } + if (!mask().equals(XCommonManager.NAV)) { + signature += " href='" + mask() + "'"; + } + return signature; + } + + /** Row selection management. + * + */ + private ActionListener actionListener = null; + + /** Registration of a single listener. + * @param listener for the unique actionListener. + */ + public final void addActionListener(final ActionListener listener) { + actionListener = listener; + } + +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/FileSelector.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/FileSelector.java new file mode 100755 index 000000000..ada9a5015 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/FileSelector.java @@ -0,0 +1,276 @@ +/* + * 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.1-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.commons.ScilabCommonsUtils; +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 boolean checkEntry; + 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.setColumns(10); + 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 (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); + textField.setCaretPosition(0); + + String dirsel = XCommonManager.getAttribute(peer, "dir-selection", "false"); + dirSelection = dirsel.equals("true"); + + String checkentry = XConfigManager.getAttribute(peer, "check-entry", "true"); + checkEntry = checkentry.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", "check-entry"}; + 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")); + + String checkentry = XConfigManager.getAttribute(peer, "check-entry", "true"); + checkEntry = checkentry.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; + } + + path = ScilabCommonsUtils.getCorrectedPath(path); + + File file = new File(path); + boolean ok = false; + if (file.exists()) { + if (dirSelection) { + ok = file.isDirectory(); + } else { + ok = file.isFile(); + } + } + + if (!checkEntry || ok) { + textField.setForeground(NORMALCOLOR); + } else { + textField.setForeground(ERRORCOLOR); + } + + return checkEntry ? ok : true; + } + + /** 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; + } + +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/FontSelector.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/FontSelector.java new file mode 100755 index 000000000..1a60d365f --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/FontSelector.java @@ -0,0 +1,262 @@ +/* + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.Dimension; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.GroupLayout; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JTextField; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; + +import org.w3c.dom.Node; + +import org.scilab.modules.gui.bridge.fontchooser.SwingScilabFontChooser; +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; + +/** + * Implementation of Label compliant with extended management. + * + * @author Calixte DENIZET + * + */ +public class FontSelector extends Panel implements XComponent, XChooser { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -4842434795956015959L; + private ActionListener actionListener; + private JTextField textField; + private JButton button; + private Font font = new Font("Monospaced", Font.PLAIN, 12); + private int defaultSize; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + return new String[] {"font-name", "font-face", "font-size", "enable"}; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public FontSelector(final Node peer) { + super(peer); + GroupLayout layout = new GroupLayout(this); + setLayout(layout); + + textField = new JTextField(); + defaultSize = textField.getFont().getSize(); + textField.setEditable(false); + + 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)); + } + } + } + }); + + layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(textField).addComponent(button)); + layout.setVerticalGroup(layout.createParallelGroup().addComponent(textField).addComponent(button)); + + setRequestFocusEnabled(true); + setFocusable(true); + + String fontname = XConfigManager.getAttribute(peer , "font-name"); + fontname(fontname); + + String fontface = XConfigManager.getAttribute(peer , "font-face"); + fontface(fontface); + + String fontsize = XConfigManager.getAttribute(peer , "font-size"); + fontsize(fontsize); + } + + private void setTextField() { + textField.setFont(font.deriveFont((float) defaultSize)); + textField.setText(fontname() + " " + fontsize() + " " + fontface()); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + String fontname = XConfigManager.getAttribute(peer , "font-name"); + if (!fontname.equals(fontname())) { + fontname(fontname); + } + + String fontface = XConfigManager.getAttribute(peer , "font-face"); + if (!fontface.equals(fontface())) { + fontface(fontface); + } + + String fontsize = XConfigManager.getAttribute(peer , "font-size"); + if (!fontsize.equals(fontsize())) { + fontsize(fontsize); + } + + String enable = XConfigManager.getAttribute(peer , "enable", "true"); + textField.setEnabled(enable.equals("true")); + button.setEnabled(enable.equals("true")); + } + + public Dimension getMaximumSize() { + return getPreferredSize(); + } + + /** Sensor for 'font-size' attribute. + * + * @return the attribute value. + */ + public final String fontsize() { + return Integer.toString(font.getSize()); + } + + /** Sensor for 'font-face' attribute. + * + * @return the attribute value. + */ + 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"; + } + } + + /** Sensor for 'font-name' attribute. + * + * @return the attribute value. + */ + public final String fontname() { + return font.getName(); + } + + /** Actuator for 'font-size' attribute. + * + * @param text : the attribute value. + */ + public final void fontsize(String fontsize) { + if (!fontsize.equals(XCommonManager.NAV) && !fontsize.equals("")) { + try { + int size = Integer.parseInt(fontsize); + font = font.deriveFont((float) size); + setTextField(); + } catch (NumberFormatException e) { } + } + } + + /** Actuator for 'font-face' attribute. + * + * @param text : the attribute value. + */ + public final void fontface(String fontface) { + if (!fontface.equals(XCommonManager.NAV) && !fontface.equals("")) { + int style = Font.PLAIN; + if (fontface.equalsIgnoreCase("bold")) { + style = Font.BOLD; + } else if (fontface.equalsIgnoreCase("italic")) { + style = Font.ITALIC; + } else if (fontface.equalsIgnoreCase("bold italic")) { + style = Font.BOLD | Font.ITALIC; + } + font = font.deriveFont(style); + setTextField(); + } + } + + /** Actuator for 'font-name' attribute. + * + * @param text : the attribute value. + */ + public final void fontname(String fontname) { + if (!fontname.equals(XCommonManager.NAV) && !fontname.equals("")) { + font = new Font(fontname, font.getStyle(), font.getSize()); + setTextField(); + } + } + + /** Actual response read by the listener. + * + * @return response read by the listener. + */ + public final Object choose() { + return new String[] {fontname(), fontface(), fontsize()}; + } + + public void addActionListener(ActionListener actionListener) { + this.actionListener = actionListener; + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + StringBuilder signature = new StringBuilder("FontSelector"); + + if (!fontname().equals(XConfigManager.NAV)) { + signature.append(" font-name='"); + signature.append(fontname()); + signature.append("'"); + } + + if (!fontface().equals(XConfigManager.NAV)) { + signature.append(" font-face='"); + signature.append(fontface()); + signature.append("'"); + } + + if (!fontsize().equals(XConfigManager.NAV)) { + signature.append(" font-size='"); + signature.append(fontsize()); + signature.append("'"); + } + + return signature.toString(); + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Grid.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Grid.java new file mode 100755 index 000000000..f0f7795cd --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Grid.java @@ -0,0 +1,174 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Insets; +import java.util.HashMap; + +import javax.swing.JPanel; + +import org.w3c.dom.Node; + +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; + +/** Implementation of Panel compliant with extended management. + * + * @author Pierre GRADIT + * + */ +public class Grid extends Panel implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = 3462302313959678932L; + private static final HashMap<String, Integer> ANCHORS = new HashMap<String, Integer>(); + + static { + ANCHORS.put("northwest", GridBagConstraints.NORTHWEST); + ANCHORS.put("north", GridBagConstraints.NORTH); + ANCHORS.put("northeast", GridBagConstraints.NORTHEAST); + ANCHORS.put("west", GridBagConstraints.WEST); + ANCHORS.put("center", GridBagConstraints.CENTER); + ANCHORS.put("east", GridBagConstraints.EAST); + ANCHORS.put("southwest", GridBagConstraints.SOUTHWEST); + ANCHORS.put("south", GridBagConstraints.SOUTH); + ANCHORS.put("southeast", GridBagConstraints.SOUTHEAST); + ANCHORS.put("first_line_start", GridBagConstraints.FIRST_LINE_START); + ANCHORS.put("page_start", GridBagConstraints.PAGE_START); + ANCHORS.put("first_line_end", GridBagConstraints.FIRST_LINE_END); + ANCHORS.put("line_start", GridBagConstraints.LINE_START); + ANCHORS.put("line_end", GridBagConstraints.LINE_END); + ANCHORS.put("last_line_start", GridBagConstraints.LAST_LINE_START); + ANCHORS.put("page_end", GridBagConstraints.PAGE_END); + ANCHORS.put("last_line_end", GridBagConstraints.LAST_LINE_END); + ANCHORS.put("baseline", GridBagConstraints.BASELINE); + ANCHORS.put("baseline_leading", GridBagConstraints.BASELINE_LEADING); + ANCHORS.put("baseline_trailing", GridBagConstraints.BASELINE_TRAILING); + ANCHORS.put("above_baseline", GridBagConstraints.ABOVE_BASELINE); + ANCHORS.put("above_baseline_leading", GridBagConstraints.ABOVE_BASELINE_LEADING); + ANCHORS.put("above_baseline_trailing", GridBagConstraints.ABOVE_BASELINE_TRAILING); + ANCHORS.put("below_baseline", GridBagConstraints.BELOW_BASELINE); + ANCHORS.put("below_baseline_leading", GridBagConstraints.BELOW_BASELINE_LEADING); + ANCHORS.put("below_baseline_trailing", GridBagConstraints.BELOW_BASELINE_TRAILING); + } + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Grid(final Node peer) { + super(peer); + setLayout(new GridBagLayout()); + //setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.RED)); + } + + /** Translation of constraints. + * + */ + void setConstraints(GridBagConstraints gbc, Object constraints) { + Node component = (Node) constraints; + gbc.gridx = XCommonManager.getInt(component, "gridx", 1) - 1; + gbc.gridy = XCommonManager.getInt(component, "gridy", 1) - 1; + gbc.gridwidth = XCommonManager.getInt(component, "gridwidth", 1); + gbc.gridheight = XCommonManager.getInt(component, "gridheight", 1); + gbc.weightx = XCommonManager.getDouble(component, "weightx", 1); + gbc.weighty = XCommonManager.getDouble(component, "weighty", 1); + gbc.ipadx = XCommonManager.getInt(component, "ipadx", 0); + gbc.ipady = XCommonManager.getInt(component, "ipady", 0); + + Integer an = ANCHORS.get(XConfigManager.getAttribute(component, "anchor").toLowerCase()); + if (an != null) { + gbc.anchor = an.intValue(); + } + + String insets = XConfigManager.getAttribute(component, "insets"); + if (insets.equals("large")) { + gbc.insets = new Insets(5, 5, 5, 5); + } else if (insets.equals("huge")) { + gbc.insets = new Insets(15, 15, 15, 15); + } + + String fill = XConfigManager.getAttribute(component, "fill"); + if (fill.equals("none")) { + gbc.fill = GridBagConstraints.NONE; + } else if (fill.equals("horizontal")) { + gbc.fill = GridBagConstraints.HORIZONTAL; + } else if (fill.equals("vertical")) { + gbc.fill = GridBagConstraints.VERTICAL; + } else if (fill.equals("both")) { + gbc.fill = GridBagConstraints.BOTH; + } + } + + /** Overloaded add method to embed grid layout. + * + */ + public void add(Component child, Object constraints, int index) { + GridBagConstraints gbc = new GridBagConstraints(); + gbc.fill = GridBagConstraints.HORIZONTAL; + + setConstraints(gbc, constraints); + super.add(child, gbc); + } + + /** Overloaded add method to embed grid layout. + * + */ + public void add(Component child, Object constraints) { + int index = getComponentCount(); + add(child, constraints, index); + } + + //TODO: + public void remove(Component child) { + getLayout().removeLayoutComponent(child); + super.remove(child); + revalidate(); + System.err.println("- - - - - REMOVE NOT IMPLEMENTABLE IN GRIDS!\n" + child); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + revalidate(); + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "VBox"; + + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/HBox b/modules/preferences/src/java/org/scilab/modules/preferences/Component/HBox new file mode 100755 index 000000000..420201136 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/HBox @@ -0,0 +1 @@ +to be deleted diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/HBox.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/HBox.java new file mode 100755 index 000000000..c2dfc61a5 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/HBox.java @@ -0,0 +1,95 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import org.scilab.modules.preferences.XComponent; + +import javax.swing.BoxLayout; +import javax.swing.JComponent; +import javax.swing.JPanel; +import org.w3c.dom.Node; +import org.scilab.modules.preferences.XConfigManager; +import java.awt.Component; + +/** + * Implementation of Panel compliant with extended management. + * + * @author Pierre GRADIT + * + */ +public class HBox extends Panel implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = 3462302313959678932L; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public HBox(final Node peer) { + super(peer); + BoxLayout box = new BoxLayout(this, BoxLayout.LINE_AXIS); + setLayout(box); + } + + /** Overloaded add method to embed grid layout. + * + */ + public void add(Component child, Object constraints, int index) { + if (child instanceof JComponent) { + ((JComponent) child).setAlignmentX(LEFT_ALIGNMENT); + ((JComponent)child).setAlignmentY(TOP_ALIGNMENT); + } + super.add(child, constraints, index); + } + + /** Overloaded add method to embed grid layout. + * + */ + public void add(Component child, Object constraints) { + if (child instanceof JComponent) { + ((JComponent)child).setAlignmentX(LEFT_ALIGNMENT); + ((JComponent)child).setAlignmentY(TOP_ALIGNMENT); + } + super.add(child, constraints); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public String toString() { + String signature = "HBox"; + + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/HTMLTextArea.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/HTMLTextArea.java new file mode 100755 index 000000000..b1f0b7ed7 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/HTMLTextArea.java @@ -0,0 +1,115 @@ +/* + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.Dimension; +import java.io.StringWriter; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextPane; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; + +/** + * Implementation of Label compliant with extended management. + * + * @author Calixte DENIZET + * + */ +public class HTMLTextArea extends JTextPane implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -4842434795956015958L; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + return new String[] {}; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public HTMLTextArea(final Node peer) { + super(); + setContentType("text/html"); + setOpaque(false); + setBorder(BorderFactory.createEmptyBorder()); + setEditable(false); + setBackground(new java.awt.Color(0, 0, 0, 0)); + + setText(dumpNode(peer)); + } + + private static String dumpNode(final Node node) { + NodeList list = node.getChildNodes(); + Node nodeToDump = null; + for (int i = 0; i < list.getLength(); i++) { + Node n = list.item(i); + if (n.getLocalName().equalsIgnoreCase("html")) { + nodeToDump = n; + break; + } + } + + if (nodeToDump != null) { + try { + Transformer serializer = TransformerFactory.newInstance().newTransformer(); + StringWriter writer = new StringWriter(); + serializer.transform(new DOMSource(nodeToDump), new StreamResult(writer)); + return writer.toString(); + } catch (Exception e) { + return nodeToDump.getTextContent(); + } + } + + return node.getTextContent(); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + String s = dumpNode(peer); + if (!s.equals(getText())) { + setText(s); + } + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + StringBuilder signature = new StringBuilder("TextArea"); + + return signature.toString(); + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Icon.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Icon.java new file mode 100755 index 000000000..a5ed9d7aa --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Icon.java @@ -0,0 +1,109 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; +import javax.swing.JLabel; +import javax.swing.ImageIcon; +import org.w3c.dom.Node; + +//TODO import org.scilab.modules.gui.bridge.label.SwingScilabLabel; +// - setIcon() and getIcon() not reachable... + +/** Implementation of Label compliant with extended management. +* +* @author Pierre GRADIT +* +*/ +public class Icon extends JLabel implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = 3026097634733924562L; + + /** Path for icons. + * + */ + public static final String SCILAB_XICONS = System.getenv("SCI") + + "/modules/gui/images/icons/16x16/actions/"; + + public static final String SCILAB_ICONS = System.getenv("SCI") + + "/modules/gui/images/icons/"; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {"src"}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Icon(final Node peer) { + super(); + + String src = XConfigManager.getAttribute(peer , "src"); + src(src); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public final void refresh(final Node peer) { + + String src = XConfigManager.getAttribute(peer , "src"); + if (!src.equals(src())) { + src(src); + } + } + + /** Sensor for 'src' attribute. + * + * @return the attribute value. + */ + public final String src() { + ImageIcon icon = (ImageIcon) getIcon(); + return icon.getDescription(); + } + + /** Actuator for 'src' attribute. + * + * @param src : the attribute value. + */ + public final void src(final String src) { + ImageIcon icon = new ImageIcon(SCILAB_XICONS + src); + if (icon.getImageLoadStatus() == 4) { + icon = new ImageIcon(SCILAB_ICONS + src); + } + icon.setDescription(src); + setIcon(icon); + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "Icon"; + + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Image.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Image.java new file mode 100755 index 000000000..36b6eb20c --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Image.java @@ -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.1-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(); + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Label.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Label.java new file mode 100755 index 000000000..c93323a78 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Label.java @@ -0,0 +1,342 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.Color; +import java.awt.Font; + +import javax.swing.JLabel; +import javax.swing.SwingConstants; + +import org.w3c.dom.Node; + +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; + +/** Implementation of Label compliant with extended management. + * + * @author Pierre GRADIT + * + */ +public class Label extends JLabel implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -4842434795956015957L; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {"text", "foreground", "background", "tooltip", "font-family", "font-face", "font-size", "enable"}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Label(final Node peer) { + super(); + + String text = XConfigManager.getAttribute(peer, "text"); + text(text); + + String tooltip = XConfigManager.getAttribute(peer, "tooltip"); + tooltip(tooltip); + + String background = XConfigManager.getAttribute(peer, "background"); + background(background); + + String foreground = XConfigManager.getAttribute(peer, "foreground"); + foreground(foreground); + + String fontFamily = XConfigManager.getAttribute(peer, "font-family", fontFamily()); + fontFamily(fontFamily); + + String fontFace = XConfigManager.getAttribute(peer, "font-face", fontFace()); + fontFace(fontFace); + + String fontSize = XConfigManager.getAttribute(peer, "font-size", fontSize()); + fontSize(fontSize); + + String enable = XConfigManager.getAttribute(peer, "enable", "true"); + setEnabled(enable.equals("true")); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + String text = XConfigManager.getAttribute(peer, "text"); + if (!text.equals(text())) { + text(text); + } + + String tooltip = XConfigManager.getAttribute(peer, "tooltip"); + if (!tooltip.equals(tooltip())) { + tooltip(tooltip); + } + + String background = XConfigManager.getAttribute(peer, "background"); + if (!background.equals(background())) { + background(background); + } + + String foreground = XConfigManager.getAttribute(peer, "foreground"); + if (!foreground.equals(foreground())) { + foreground(foreground); + } + + String fontFamily = XConfigManager.getAttribute(peer, "font-family", fontFamily()); + if (!fontFamily.equals(fontFamily())) { + fontFamily(fontFamily); + } + + String fontFace = XConfigManager.getAttribute(peer, "font-face", fontFace()); + if (!fontFace.equals(fontFace())) { + fontFace(fontFace); + } + + String fontSize = XConfigManager.getAttribute(peer, "font-size", fontSize()); + if (!fontSize.equals(fontSize())) { + fontSize(fontSize); + } + + String halign = XConfigManager.getAttribute(peer, "halign", "left"); + if (halign.equals("left")) { + setHorizontalAlignment(SwingConstants.LEFT); + } + if (halign.equals("right")) { + setHorizontalAlignment(SwingConstants.RIGHT); + } + + String enable = XConfigManager.getAttribute(peer, "enable", "true"); + setEnabled(enable.equals("true")); + } + + /** Sensor for 'text' attribute. + * + * @return the attribute value. + */ + public final String text() { + return getText(); + } + + /** Sensor for 'tooltip' attribute. + * + * @return the attribute value. + */ + public final String tooltip() { + String tooltip = getToolTipText(); + if (tooltip == null) { + return ""; + } + return tooltip; + } + + /** Sensor for 'foreground' attribute. + * + * @return the attribute value. + */ + public final String foreground() { + return XConfigManager.getColor(getForeground()); + } + + /** Sensor for 'background' attribute. + * + * @return the attribute value. + */ + public final String background() { + Color fg = getForeground(); + if (fg != null && fg.equals(getParent().getBackground())) { + return XConfigManager.NAV; + } else { + return XConfigManager.getColor(getBackground()); + } + } + + /** Sensor for 'font-family' attribute. + * + * @return the attribute value. + */ + public final String fontFamily() { + return getFont().getFamily(); + } + + /** Sensor for 'font-size' attribute. + * + * @return the attribute value. + */ + public final String fontSize() { + return "" + getFont().getSize(); + } + + /** Sensor for 'font-face' attribute. + * + * @return the attribute value. + */ + public final String fontFace() { + switch (getFont().getStyle()) { + case Font.PLAIN : + return "plain"; + case Font.ITALIC : + return "italic"; + case Font.BOLD : + return "bold"; + case 3 : + return "bold italic"; + } + return XCommonManager.NAV; + } + + /** Actuator for 'font-family' attribute. + * + * @return the attribute value. + */ + public final void fontFamily(String fontFamily) { + Font font = new Font( + fontFamily, + getFont().getStyle(), + getFont().getSize()); + setFont(font); + } + + /** Actuator for 'font-size' attribute. + * + * @return the attribute value. + */ + public final void fontSize(String fontSize) { + Font font = new Font( + getFont().getFamily(), + getFont().getStyle(), + Integer.parseInt(fontSize)); + setFont(font); + } + + /** Accelerator for 'font-face' actuator. + * + * @param xFace + * @return + */ + private int getStyle(String xFace) { + if (xFace.equals("plain")) { + return Font.PLAIN; + } + if (xFace.equals("italic")) { + return Font.ITALIC; + } + if (xFace.equals("bold")) { + return Font.BOLD; + } + if (xFace.equals("bold italic")) { + return Font.BOLD + Font.ITALIC; + } + return -1; + } + /** Actuator for 'font-face' attribute. + * + * @return the attribute value. + */ + public final void fontFace(String fontFace) { + Font font = new Font( + getFont().getFamily(), + getStyle(fontFace), + getFont().getSize()); + setFont(font); + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void text(final String text) { + setText(text); + } + + /** Actuator for 'tooltip' attribute. + * + * @param text : the attribute value. + */ + public final void tooltip(String tooltip) { + if (tooltip.equals(XCommonManager.NAV) + || tooltip.equals("") + ) { + tooltip = null; + } + setToolTipText(tooltip); + } + + /** Actuator for 'foreground' attribute. + * + * @param foreground : the attribute value. + */ + public final void foreground(final String foreground) { + if (foreground.equals(XConfigManager.NAV)) { + setForeground(null); + } else { + Color color = XConfigManager.getColor(foreground); + //System.err.println("foreground:" + actuator + " = " + color); + setForeground(color); + } + } + + /** Actuator for 'background' attribute. + * + * @param background : the attribute value. + */ + public final void background(final String background) { + if (background.equals(XConfigManager.NAV)) { + setOpaque(false); + setBackground(null); + } else { + Color color = XConfigManager.getColor(background); + //System.err.println("background:" + actuator + " = " + color); + setOpaque(true); + setBackground(color); + } + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "Label"; + + if (!text().equals(XConfigManager.NAV)) { + signature += " text='" + text() + "'"; + } + if (!background().equals(XConfigManager.NAV)) { + signature += " background='" + background() + "'"; + } + if (!foreground().equals(XConfigManager.NAV)) { + signature += " foreground='" + foreground() + "'"; + } + if (!fontFamily().equals(XConfigManager.NAV)) { + signature += " font-family='" + fontFamily() + "'"; + } + if (!fontFace().equals(XConfigManager.NAV)) { + signature += " font-face='" + fontFace() + "'"; + } + if (!fontSize().equals(XConfigManager.NAV)) { + signature += " font-size='" + fontSize() + "'"; + } + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Link.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Link.java new file mode 100755 index 000000000..8c65d9b75 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Link.java @@ -0,0 +1,62 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - DIGITEO - Vincent COUVERT + * + * 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.1-en.txt + * + */ + +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(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()); + } + } + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/List.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/List.java new file mode 100755 index 000000000..8380fe121 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/List.java @@ -0,0 +1,233 @@ +/* + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JList; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.AbstractListModel; + +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** Implementation of Select compliant with extended management. + * + * @author Calixte DENIZET + * + */ +public class List extends Panel implements XComponent, XChooser, ListSelectionListener { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -6127289363733321915L; + + private ActionListener actionListener; + private Model model; + private JList list; + private boolean dontChange; + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public List(final Node peer) { + super(peer); + model = new Model(peer); + list = new JList(model); + list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.getSelectionModel().addListSelectionListener(this); + JScrollPane scrollPane = new JScrollPane(list); + add(scrollPane); + list.setRequestFocusEnabled(true); + list.setFocusable(true); + + refresh(peer); + } + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String[] actuators = {"item", "enable", "nb-visible-rows"}; + return actuators; + } + + public void valueChanged(ListSelectionEvent e) { + if (actionListener != null && !dontChange && !e.getValueIsAdjusting()) { + actionListener.actionPerformed(new ActionEvent(this, 0, "List selected Value changed", System.currentTimeMillis(), 0)); + } + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public final void refresh(final Node peer) { + model.setNodeList(peer.getChildNodes()); + String item = XCommonManager.getAttribute(peer , "item"); + if (!item.equals(item())) { + item(item); + } + + String nbvisible = XCommonManager.getAttribute(peer , "nb-visible-rows", "5"); + if (!nbvisible.equals(nbvisible())) { + nbvisible(nbvisible); + } + + String enable = XConfigManager.getAttribute(peer , "enable", "true"); + setEnabled(enable.equals("true")); + } + + /** Actual response read by the listener. + * + * @return the chosen value. + */ + public final Object choose() { + return item(); + } + + /** Registration of a single listener. + * @param listener for the unique actionListener. + */ + public final void addActionListener(final ActionListener listener) { + actionListener = listener; + } + + /** Sensor for 'item' attribute. + * + * @return the attribute value. + */ + public final String item() { + Object value = list.getSelectedValue(); + if (value == null) { + value = model.getElementAt(0); + list.setSelectedValue(value, true); + } + + return value.toString(); + } + + /** Actuator for 'item' attribute. + * + * @param text : the attribute value. + */ + public final void item(final String item) { + if (!item.equals(XCommonManager.NAV) && !item.equals("")) { + dontChange = true; + list.setSelectedValue(item, true); + dontChange = false; + } + } + + /** Sensor for 'nb-visible-rows' attribute. + * + * @return the attribute value. + */ + public final String nbvisible() { + return Integer.toString(list.getVisibleRowCount()); + } + + /** Actuator for 'item' attribute. + * + * @param text : the attribute value. + */ + public final void nbvisible(final String nbvisible) { + if (!nbvisible.equals(XCommonManager.NAV) && !nbvisible.equals("")) { + try { + int nb = Integer.parseInt(nbvisible); + list.setVisibleRowCount(nb); + } catch (NumberFormatException e) { } + } + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "List ..."; + return signature; + } + + /** + * Scans DOM nodes and translate it into list model. + */ + class Model extends AbstractListModel { + + /** + * Serialization ID. + */ + private static final long serialVersionUID = -4786321481195930071L; + + /** Data source. + * + */ + private NodeList nodelist; + + public Model(Node peer) { + setNodeList(peer.getChildNodes()); + } + + public void setNodeList(NodeList list) { + nodelist = list; + } + + /** + * {@inheritDoc} + */ + public Object getElementAt(int index) { + int count = index; + for (int i = 0; i < nodelist.getLength(); i++) { + Node node = nodelist.item(i); + if (node.getNodeName().equals("listElement")) { + if (count == 0) { + return XCommonManager.getAttribute(node, "name"); + } + count--; + } + } + return null; + } + + /** + * {@inheritDoc} + */ + public int getSize() { + int count = 0; + for (int i = 0; i < nodelist.getLength(); i++) { + Node node = nodelist.item(i); + if (node.getNodeName().equals("listElement")) { + count++; + } + } + return count; + } + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/NumericalSpinner.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/NumericalSpinner.java new file mode 100755 index 000000000..425d79693 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/NumericalSpinner.java @@ -0,0 +1,317 @@ +/* + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JPanel; +import javax.swing.JSpinner; +import javax.swing.SpinnerNumberModel; +import javax.swing.SwingConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import org.w3c.dom.Node; + +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; + +/** + * Implementation of Label compliant with extended management. + * + * @author Calixte DENIZET + * + */ +public class NumericalSpinner extends JSpinner implements XComponent, XChooser, ChangeListener { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -4842434795956015958L; + private static final Double defaultInc = new Double(1); + + private Double min = new Double(Double.NEGATIVE_INFINITY); + private Double max = new Double(Double.POSITIVE_INFINITY); + private SpinnerNumberModel spinnerModel; + private ActionListener actionListener; + + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + return new String[] {"length", "increment", "min-value", "max-value", "value", "tooltip", "enable"}; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public NumericalSpinner(final Node peer) { + super(); + spinnerModel = new SpinnerNumberModel(new Double(0), min, max, defaultInc); + setModel(spinnerModel); + addChangeListener(this); + + String length = XConfigManager.getAttribute(peer, "length"); + length(length); + + String increment = XConfigManager.getAttribute(peer, "increment"); + increment(increment); + + String tooltip = XConfigManager.getAttribute(peer, "tooltip"); + tooltip(tooltip); + + String minvalue = XConfigManager.getAttribute(peer, "min-value"); + minvalue(minvalue); + + String maxvalue = XConfigManager.getAttribute(peer, "max-value"); + maxvalue(maxvalue); + + String value = XConfigManager.getAttribute(peer, "value"); + value(value); + + String enable = XConfigManager.getAttribute(peer, "enable", "true"); + setEnabled(enable.equals("true")); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + String length = XConfigManager.getAttribute(peer, "length"); + if (!length.equals(length())) { + length(length); + } + + String increment = XConfigManager.getAttribute(peer, "increment"); + if (!increment.equals(increment())) { + increment(increment); + } + + String tooltip = XConfigManager.getAttribute(peer, "tooltip"); + if (!tooltip.equals(tooltip())) { + tooltip(tooltip); + } + + String minvalue = XConfigManager.getAttribute(peer, "min-value"); + if (!minvalue.equals(minvalue())) { + minvalue(minvalue); + } + + String maxvalue = XConfigManager.getAttribute(peer, "max-value"); + if (!maxvalue.equals(maxvalue())) { + maxvalue(maxvalue); + } + + String value = XConfigManager.getAttribute(peer, "value"); + if (!value.equals(value())) { + value(value); + } + + String enable = XConfigManager.getAttribute(peer, "enable", "true"); + setEnabled(enable.equals("true")); + + setRequestFocusEnabled(true); + setFocusable(true); + } + + /** Sensor for 'length' attribute. + * + * @return the attribute value. + */ + public final String length() { + return Integer.toString(((JSpinner.DefaultEditor) getEditor()).getTextField().getColumns()); + } + + /** Sensor for 'value' attribute. + * + * @return the attribute value. + */ + public final String value() { + return spinnerModel.getValue().toString(); + } + + /** Sensor for 'min-value' attribute. + * + * @return the attribute value. + */ + public final String minvalue() { + return spinnerModel.getMinimum().toString(); + } + + /** Sensor for 'max-value' attribute. + * + * @return the attribute value. + */ + public final String maxvalue() { + return spinnerModel.getMaximum().toString(); + } + + /** Sensor for 'increment' attribute. + * + * @return the attribute value. + */ + public final String increment() { + return spinnerModel.getStepSize().toString(); + } + + /** Sensor for 'tooltip' attribute. + * + * @return the attribute value. + */ + public final String tooltip() { + String tooltip = getToolTipText(); + if (tooltip == null) { + return ""; + } + return tooltip; + } + + /** Actuator for 'length' attribute. + * + * @param text : the attribute value. + */ + public final void length(String length) { + if (!length.equals(XCommonManager.NAV) && !length.equals("")) { + try { + ((JSpinner.DefaultEditor) getEditor()).getTextField().setColumns(Integer.parseInt(length)); + } catch (NumberFormatException e) { } + } + } + + /** Actuator for 'tooltip' attribute. + * + * @param text : the attribute value. + */ + public final void tooltip(String tooltip) { + if (tooltip.equals(XCommonManager.NAV) || tooltip.equals("")) { + tooltip = null; + } + setToolTipText(tooltip); + } + + /** Actuator for 'value' attribute. + * + * @return the attribute value. + */ + public final void value(String value) { + if (!value.equals(XCommonManager.NAV) && !value.equals("")) { + spinnerModel.setValue(new Double(value)); + } + } + + /** Actuator for 'min-value' attribute. + * + * @return the attribute value. + */ + public final void minvalue(String minvalue) { + if (!minvalue.equals(XCommonManager.NAV) && !minvalue.equals("")) { + try { + spinnerModel.setMinimum(new Double(minvalue)); + } catch (NumberFormatException e) { } + } + } + + /** Actuator for 'max-value' attribute. + * + * @return the attribute value. + */ + public final void maxvalue(String maxvalue) { + if (!maxvalue.equals(XCommonManager.NAV) && !maxvalue.equals("")) { + try { + spinnerModel.setMaximum(new Double(maxvalue)); + } catch (NumberFormatException e) { } + } + } + + /** Actuator for 'max-value' attribute. + * + * @return the attribute value. + */ + public final void increment(String increment) { + if (increment.equals(XCommonManager.NAV) || increment.equals("")) { + spinnerModel.setStepSize(defaultInc); + } else { + try { + spinnerModel.setStepSize(new Double(increment)); + } catch (NumberFormatException e) { } + } + } + + /** Actual response read by the listener. + * + * @return response read by the listener. + */ + public final Object choose() { + return value(); + } + + /** + * {@inheritDoc} + */ + public void stateChanged(ChangeEvent e) { + if (actionListener != null) { + actionListener.actionPerformed(new ActionEvent(this, 0, "Spinner Value changed", System.currentTimeMillis(), 0)); + } + } + + public void addActionListener(ActionListener actionListener) { + this.actionListener = actionListener; + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + StringBuilder signature = new StringBuilder("NumericalSpinner"); + + if (!length().equals(XConfigManager.NAV)) { + signature.append(" length='"); + signature.append(length()); + signature.append("'"); + } + + if (!value().equals(XConfigManager.NAV)) { + signature.append(" value='"); + signature.append(value()); + signature.append("'"); + } + + if (!minvalue().equals(XConfigManager.NAV)) { + signature.append(" min-value='"); + signature.append(minvalue()); + signature.append("'"); + } + + if (!maxvalue().equals(XConfigManager.NAV)) { + signature.append(" max-value='"); + signature.append(maxvalue()); + signature.append("'"); + } + + if (!increment().equals(XConfigManager.NAV)) { + signature.append(" increment='"); + signature.append(increment()); + signature.append("'"); + } + + return signature.toString(); + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Panel.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Panel.java new file mode 100755 index 000000000..ba07a1295 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Panel.java @@ -0,0 +1,129 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.BorderLayout; +import java.awt.Dimension; + +import javax.swing.JPanel; + +import org.w3c.dom.Node; + +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; + +/** Implementation of Panel compliant with extended management. + * + * @author Pierre GRADIT + * + */ +public class Panel extends JPanel implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = 3462302313959678932L; + + protected boolean fixedHeight = true; + protected boolean fixedWidth = false; + private Dimension maxDim = new Dimension(0, 0); + private Dimension minDim = new Dimension(0, 0); + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public String [] actuators() { + return new String[] {}; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Panel(final Node peer) { + super(); + setLayout(new BorderLayout()); + XConfigManager.setDimension(this, peer); + + String fixed = XConfigManager.getAttribute(peer, "fixed-width"); + if (!(fixed.equals(XConfigManager.NAV))) { + this.fixedWidth = fixed.equals("true"); + } + + fixed = XConfigManager.getAttribute(peer, "fixed-height"); + if (!(fixed.equals(XConfigManager.NAV))) { + this.fixedHeight = fixed.equals("true"); + } + + //setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.GREEN)); + } + + /** + * {@inheritDoc} + */ + public Dimension getMaximumSize() { + Dimension max = super.getMaximumSize(); + if (fixedHeight) { + maxDim.height = getPreferredSize().height; + } else { + maxDim.height = max.height; + } + + if (fixedWidth) { + maxDim.width = getPreferredSize().width; + } else { + maxDim.width = max.width; + } + + return maxDim; + } + + /** + * {@inheritDoc} + */ + public Dimension getMinimumSize() { + Dimension min = super.getMinimumSize(); + if (fixedHeight) { + minDim.height = getPreferredSize().height; + } else { + minDim.height = min.height; + } + + if (fixedWidth) { + minDim.width = getPreferredSize().width; + } else { + minDim.width = min.width; + } + + return minDim; + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public String toString() { + String signature = "Panel"; + + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/PreviewCode.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/PreviewCode.java new file mode 100755 index 000000000..9f86f6f44 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/PreviewCode.java @@ -0,0 +1,190 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.Color; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; + +import javax.swing.JScrollPane; +import javax.swing.text.DefaultCaret; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.scilab.modules.commons.ScilabCommonsUtils; +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; +import org.scilab.modules.scinotes.KeywordAdapter; +import org.scilab.modules.scinotes.KeywordEvent; +import org.scilab.modules.scinotes.ScilabEditorPane; +import org.scilab.modules.scinotes.ScilabEditorKit; +import org.scilab.modules.scinotes.ScilabLexerConstants; + +/** Implementation of Panel compliant with extended management. + * + * @author Pierre GRADIT + * + */ +@SuppressWarnings(value = { "serial" }) +public class PreviewCode extends Panel implements XComponent, XChooser { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = 3462302313959678932L; + private static final int GAP = 5; + + private final ScilabEditorPane previewEditorPane; + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public PreviewCode(final Node peer) { + super(peer); + fixedHeight = false; + previewEditorPane = new ScilabEditorPane(null); + ScilabEditorKit kit = new ScilabEditorKit(); + previewEditorPane.setEditorKit(kit); + previewEditorPane.setFont(kit.getStylePreferences().tokenFonts[0]); + String codeSample = "// A comment with whites and tabulations \t\t\n" + + "// Email: <support@scilab-enterprises.com>\n" + + "// Scilab editor: http://www.scilab-enterprises.com/\n" + + "//\n" + + "// LaTeX $$\\sum_{n=1}^{+\\infty}\\frac1{n^2}=\\frac{\\pi^2}6$$\n" + + "// TODO: blah blah\n" + + "function [a, b] = myfunction(d, e, f)\n" + + "\ta = 2.71828 + %pi + f($, :);\n" + + "\tb = cos(a) + cosh(a) + \"$\\frac12$\";\n" + + "\tif d == e then\n" + + "\t\tb = 10 - e.field;\n" + + "\telse\n" + + "\t\tb = \"\t\ttest \" + home\n" + + "\t\treturn\n" + + "\tend\n" + + "\tmyvar = 1.23e-45;\n" + + "endfunction"; + previewEditorPane.setText(codeSample); + previewEditorPane.setCaret(new DefaultCaret() { + public void mouseDragged(MouseEvent e) { + e.consume(); + } + }); + previewEditorPane.setBackground(Color.WHITE); + previewEditorPane.getCaret().setBlinkRate(500); + previewEditorPane.getCaret().setVisible(true); + previewEditorPane.setEditable(false); + previewEditorPane.addKeywordListener(new KeywordAdapter.MouseOverAdapter() { + public void caughtKeyword(KeywordEvent e) { + previewEditorPane.setToolTipText(ScilabLexerConstants.getStringRep(e.getType())); + } + }); + previewEditorPane.addKeywordListener(new KeywordAdapter.MouseClickedAdapter() { + public void caughtKeyword(KeywordEvent e) { + PreviewCode.this.keywordClicked(e); + } + }); + JScrollPane scrollPane = new JScrollPane(previewEditorPane); + previewEditorPane.setRequestFocusEnabled(true); + previewEditorPane.setFocusable(true); + + add(scrollPane); + } + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {}; + return actuators; + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + NodeList nodelist = peer.getChildNodes(); + for (int i = 0; i < nodelist.getLength(); i++) { + Node node = nodelist.item(i); + if (node.getNodeName().equals("tableRow")) { + String name = XConfigManager.getAttribute(node , "name"); + String xColor = XConfigManager.getAttribute(node , "color"); + Color color = XConfigManager.getColor(xColor); + previewEditorPane.resetColor(name, color); + int style = 0; + if (XConfigManager.getAttribute(node , "underline").equals("true")) { + style = 1; + } + if (XConfigManager.getAttribute(node , "strike-through").equals("true")) { + style += 2; + } + previewEditorPane.resetAttribute(name, style); + int bold = -1; + if (XConfigManager.getAttribute(node , "bold").equals("true")) { + bold = 1; + } + int italic = -2; + if (XConfigManager.getAttribute(node , "italic").equals("true")) { + italic = 2; + } + previewEditorPane.resetFont(name, bold); + previewEditorPane.resetFont(name, italic); + } + } + previewEditorPane.repaint(); + } + + /** Row selection management. + * + */ + private ActionListener actionListener = null; + String chosenItem; + + /** Actual response read by the listener. + * + * @return index of the selected line. + */ + public final Object choose() { + return chosenItem; + } + + public void keywordClicked(KeywordEvent e) { + if (actionListener != null) { + int choosedIndex = e.getType(); + chosenItem = ScilabLexerConstants.getStringRep(choosedIndex); + ActionEvent transmit = new ActionEvent(this, 0, "Keyword changed", System.currentTimeMillis(), 0); + actionListener.actionPerformed(transmit); + } + } + + /** Registration of a single listener. + * @param listener for the unique actionListener. + */ + public final void addActionListener(final ActionListener listener) { + actionListener = listener; + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + return "PreviewCode"; + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Radiobutton.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Radiobutton.java new file mode 100755 index 000000000..7b7d9b58b --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Radiobutton.java @@ -0,0 +1,161 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XConfigManager; +import org.scilab.modules.gui.bridge.radiobutton.SwingScilabRadioButton; + +import org.w3c.dom.Node; + +/** Implementation of Radiobutton compliant with extended management. + * + * @author Pierre GRADIT + * + */ +public class Radiobutton extends SwingScilabRadioButton implements XComponent, XChooser { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -7007541669965737408L; + + private String expectedValue; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {"enable", "text", "checked", "value", "expected-value"}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Radiobutton(final Node peer) { + super(); + setOpaque(false); + refresh(peer); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public final void refresh(final Node peer) { + String text = XConfigManager.getAttribute(peer, "text"); + if (!text.equals(text())) { + text(text); + } + + 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")); + } + + /** Sensor for 'text' attribute. + * + * @return the attribute value. + */ + public final String text() { + String text = getText(); + if (text != null) { + return text; + } else { + return XConfigManager.NAV; + } + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void text(final String text) { + if (text != XConfigManager.NAV) { + setText(text); + } else { + setText(null); + } + } + + /** Sensor for 'checked' attribute. + * + * @return the attribute value. + */ + public final String checked() { + boolean state = isSelected(); + if (state) { + return "checked"; + } else { + return "unchecked"; + } + } + + /** Actuator for 'checked' attribute. + * + * @param text : the attribute value. + */ + public final void checked(final String checked) { + boolean state = checked.equals("checked"); + setSelected(state); + } + + /** Actual response read by the listener. + * + * @return response read by the listener. + */ + public final Object choose() { + if (expectedValue != null) { + return expectedValue; + } + + if (isSelected()) { + return "checked"; + } + return "unchecked"; + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "RadioButton"; + if (!text().equals(XConfigManager.NAV)) { + signature += " text='" + text() + "'"; + } + if (!checked().equals(XConfigManager.NAV)) { + signature += " checked='" + checked() + "'"; + } + return signature; + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/ScilabDoubleEntry.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/ScilabDoubleEntry.java new file mode 100755 index 000000000..8b1b39a85 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/ScilabDoubleEntry.java @@ -0,0 +1,147 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2012 - Scilab Enterprises - Clement DAVID + * + * 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.1-en.txt + * + */ +package org.scilab.modules.preferences.Component; + +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; + +import javax.swing.InputVerifier; +import javax.swing.JFormattedTextField; + +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; +import org.w3c.dom.Node; + +/** + * {@link Entry} component which only allow a Scilab single double data text. + */ +@SuppressWarnings(value = { "serial" }) +public class ScilabDoubleEntry extends JFormattedTextField implements XComponent, XChooser { + + /* + * Static things, modify the following lines in case of a format change + */ + + private static final DecimalFormatSymbols FORMAT_SYMBOL = DecimalFormatSymbols.getInstance(); + private static final DecimalFormat SCILAB_FORMAT = new DecimalFormat("0.0####E00", FORMAT_SYMBOL); + private static final BigDecimal MAX_DOUBLE = BigDecimal.valueOf(Double.MAX_VALUE); + + /** + * Validate the user entry and format it. + * + * Without formatting the entry, bug #7143 appears on jdk6. + */ + private static final InputVerifier VALIDATE_POSITIVE_DOUBLE = new InputVerifier() { + + @Override + public boolean verify(javax.swing.JComponent arg0) { + boolean ret = false; + JFormattedTextField textField = (JFormattedTextField) arg0; + try { + BigDecimal value = new BigDecimal(textField.getText()); + if (value.compareTo(BigDecimal.ZERO) >= 0 && value.compareTo(MAX_DOUBLE) <= 0) { + ret = true; + } + } catch (NumberFormatException e) { + return ret; + } + return ret; + + }; + }; + + /** + * Initialize static final fields + */ + static { + FORMAT_SYMBOL.setDecimalSeparator('.'); + SCILAB_FORMAT.setDecimalFormatSymbols(FORMAT_SYMBOL); + SCILAB_FORMAT.setParseIntegerOnly(false); + SCILAB_FORMAT.setParseBigDecimal(true); + } + + /** + * Constructor. + * + * @param peer + * : associated view DOM node. + */ + public ScilabDoubleEntry(final Node peer) { + super(SCILAB_FORMAT); + setValue(new BigDecimal(0.0)); + setInputVerifier(VALIDATE_POSITIVE_DOUBLE); + + refresh(peer); + } + + /* + * Actuators + */ + + public final String value() { + return ((BigDecimal) getValue()).toPlainString(); + } + + public final void value(final String text) { + try { + setValue(new BigDecimal(text)); + } catch (NumberFormatException e) { + // do not update + } + } + + /* + * XChooser implementation + * + * @see org.scilab.modules.preferences.XChooser + */ + + @Override + public Object choose() { + return SCILAB_FORMAT.format(getValue()); + } + + /* + * XComponent implementation + * + * @see org.scilab.modules.preferences.XComponent + */ + + @Override + public String[] actuators() { + String[] actuators = { "enable", "value", "editable" }; + return actuators; + } + + @Override + public void refresh(Node peer) { + final String enable = XConfigManager.getAttribute(peer, "enable", "true"); + setEnabled(enable.equals("true")); + + final String text = XCommonManager.getAttribute(peer, "value"); + try { + final BigDecimal value = new BigDecimal(text); + final BigDecimal previous = (BigDecimal) getValue(); + if (!value.equals(previous)) { + setValue(value); + } + } catch (NumberFormatException e) { + // do not update + } + + final String editable = XConfigManager.getAttribute(peer, "editable", "true"); + setEditable(editable.equals("true")); + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Scroll.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Scroll.java new file mode 100755 index 000000000..5acdaa860 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Scroll.java @@ -0,0 +1,139 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import org.scilab.modules.preferences.XComponent; +import javax.swing.JScrollPane; +import org.w3c.dom.Node; +import org.scilab.modules.preferences.XConfigManager; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; + +import javax.swing.BorderFactory; + +/** Implementation of Scroll compliant with extended management. +* +* @author Pierre GRADIT +* +*/ +public class Scroll extends JScrollPane implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -6203963304355019727L; + + /** Constructor. + * + * @param peer : associated view DOM node. + * @param component : parent component. + */ + public Scroll(final Node peer, final Component component) { + super(component); + insideContainer = (Container) component; + insideContainer.setLayout(new BorderLayout()); + setMinimumSize(new Dimension(200, 200)); + XConfigManager.setDimension(this, peer); + setBorder(BorderFactory.createEmptyBorder()); + setViewportBorder(BorderFactory.createEmptyBorder()); + } + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {}; + return actuators; + } + + /** Inside panel. + * + */ + private Container insideContainer; + + /** Add to container except for system adds. + * + * @param component : associated view DOM node. + * @param constraints : associated view DOM node. + */ + public final void add(final Component component, final Object constraints) { + if (component instanceof XComponent) { + insideContainer.add(component, constraints); + return; + } + super.add(component, constraints); + } + + /** Add to container except for system adds. + * + * @param component : associated view DOM node. + * @param constraints : associated view DOM node. + * @param index : order number in layout. + */ + public final void add( + final Component component, + final Object constraints, + final int index) { + if (component instanceof XComponent) { + insideContainer.add(component, constraints, index); + return; + } + super.add(component, constraints, index); + } + + /** Remove from container. + * + * @param component : associated view DOM node. + */ + public final void remove(final Component component) { + insideContainer.remove(component); + } + + /** Children consultation. + * + * @return container component count + */ + public final int getXComponentCount() { + return insideContainer.getComponentCount(); + } + + /** Children consultation. + * + * @param index : order number in layout. + * @return indexed component + */ + public final Component getXComponent(final int index) { + return insideContainer.getComponent(index); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "Scroll"; + + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Select.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Select.java new file mode 100755 index 000000000..37da5c668 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Select.java @@ -0,0 +1,131 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.Dimension; +import java.util.HashMap; +import java.util.Map; + +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XConfigManager; +import javax.swing.JComboBox; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** Implementation of Select compliant with extended management. +* +* @author Pierre GRADIT +* +*/ +public class Select extends JComboBox implements XComponent, XChooser { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -6127289363733321914L; + private Map<String, String> map; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {"enable"}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Select(final Node peer) { + super(); + //setMinimumSize(new Dimension(200,30)); + //setPreferredSize(new Dimension(200,30)); + NodeList nodelist = peer.getChildNodes(); + int select = 0; + int index = 0; + map = new HashMap<String, String>(); + for (int i = 0; i < nodelist.getLength(); i++) { + Node node = nodelist.item(i); + if (node.getNodeName().equals("option")) { + String value = XConfigManager.getAttribute(node, "value"); + String key = XConfigManager.getAttribute(node, "key"); + String selected = XConfigManager.getAttribute(node, "selected"); + addItem(value); + if (selected.equals("selected")) { + select = index; + } + ++index; + if (key.equals(XCommonManager.NAV)) { + map.put(value, value); + } else { + map.put(value, key); + } + } + } + + if (select < getItemCount()) { + setSelectedIndex(select); + } + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + NodeList nodelist = peer.getChildNodes(); + int select = 0; + int index = 0; + for (int i = 0; i < nodelist.getLength(); i++) { + Node node = nodelist.item(i); + if (node.getNodeName().equals("option")) { + String selected = XConfigManager.getAttribute(node , "selected"); + if (selected.equals("selected")) { + select = index; + } + ++index; + } + } + if (select != getSelectedIndex() && select < getItemCount()) { + setEnabled(false); + setSelectedIndex(select); + } + String enable = XConfigManager.getAttribute(peer, "enable", "true"); + setEnabled(enable.equals("true")); + } + + /** Actual response read by the listener. + * + * @return response read by the listener. + */ + public final Object choose() { + if (isEnabled()) { + return map.get((String) getSelectedItem()); + } + return null; + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "Select"; + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Slider.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Slider.java new file mode 100755 index 000000000..162ca90c6 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Slider.java @@ -0,0 +1,184 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - DIGITEO - Vincent COUVERT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.Color; + +import org.scilab.modules.gui.bridge.slider.SwingScilabSlider; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XComponentAttributes; +import org.scilab.modules.preferences.XConfigManager; +import org.w3c.dom.Node; + +/** + * Implementation of Label compliant with extended management. + * @author Vincent COUVERT + * + */ +public class Slider extends SwingScilabSlider implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -4842434795956015957L; + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Slider(final Node peer) { + super(); + setHorizontal(); + + String tooltip = XConfigManager.getAttribute(peer , XComponentAttributes.TOOLTIP); + tooltip(tooltip); + + String background = XConfigManager.getAttribute(peer , XComponentAttributes.BACKGROUND); + background(background); + + String foreground = XConfigManager.getAttribute(peer , XComponentAttributes.FOREGROUND); + foreground(foreground); + } + + /** + * Define the set of actuators. + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {XComponentAttributes.FOREGROUND, + XComponentAttributes.BACKGROUND, + XComponentAttributes.TOOLTIP + }; + return actuators; + } + + /** + * Refresh the component by the use of actuators. + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + + String tooltip = XConfigManager.getAttribute(peer , "tooltip"); + if (!tooltip.equals(tooltip())) { + tooltip(tooltip); + } + + String background = XConfigManager.getAttribute(peer , "background"); + if (!background.equals(background())) { + background(background); + } + + String foreground = XConfigManager.getAttribute(peer , "foreground"); + if (!foreground.equals(foreground())) { + foreground(foreground); + } + + setRequestFocusEnabled(true); + setFocusable(true); + } + + /** Sensor for 'tooltip' attribute. + * + * @return the attribute value. + */ + public final String tooltip() { + String tooltip = getToolTipText(); + if (tooltip == null) { + return ""; + } + return tooltip; + } + + /** Sensor for 'foreground' attribute. + * + * @return the attribute value. + */ + public final String foreground() { + if (getForeground().equals(getParent().getForeground())) { + return XConfigManager.NAV; + } else { + return XConfigManager.getColor(getForeground()); + } + } + + /** Sensor for 'background' attribute. + * + * @return the attribute value. + */ + public final String background() { + if (getForeground().equals(getParent().getBackground())) { + return XConfigManager.NAV; + } else { + return XConfigManager.getColor(getBackground()); + } + } + + + /** + * Actuator for 'tooltip' attribute. + * @param tooltip : the attribute value. + */ + public final void tooltip(String tooltip) { + if (tooltip.equals(XCommonManager.NAV) || tooltip.equals("")) { + setToolTipText(null); + } else { + setToolTipText(tooltip); + } + } + + /** + * Actuator for 'foreground' attribute. + * @param foreground : the attribute value. + */ + public final void foreground(final String foreground) { + if (foreground.equals(XConfigManager.NAV)) { + setForeground(null); + } else { + Color color = XConfigManager.getColor(foreground); + setForeground(color); + } + } + + /** + * Actuator for 'background' attribute. + * @param background : the attribute value. + */ + public final void background(final String background) { + if (background.equals(XConfigManager.NAV)) { + setOpaque(false); + setBackground(null); + } else { + Color color = XConfigManager.getColor(background); + setOpaque(true); + setBackground(color); + } + } + + /** + * Developer serialization method. + * @return equivalent signature. + */ + public final String toString() { + String signature = "Label"; + + if (!background().equals(XConfigManager.NAV)) { + signature += " background='" + background() + "'"; + } + if (!foreground().equals(XConfigManager.NAV)) { + signature += " foreground='" + foreground() + "'"; + } + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Table.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Table.java new file mode 100755 index 000000000..dccf2ab26 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Table.java @@ -0,0 +1,522 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; + + +/** Implementation of Select compliant with extended management. + * + * @author Pierre GRADIT + * + */ +@SuppressWarnings(value = { "serial" }) +public class Table extends Panel implements XComponent, XChooser, ListSelectionListener, ActionListener { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -6127289363733321914L; + + private final CustomTableCellRenderer customTableCellRenderer = new CustomTableCellRenderer(); + private Model model; + private JTable table; + private JScrollPane scrollPane; + + /** The attribute column indicates which column has to be chosen. + * if this attribute is not set, the chosen value is the selected index (as a string). + */ + private String column; + + //begin Dynamic_controller + // TODO separate class. + private ImageIcon icons[] = { + new ImageIcon(Icon.SCILAB_XICONS + "list-add.png"), + new ImageIcon(Icon.SCILAB_XICONS + "go-up.png"), + new ImageIcon(Icon.SCILAB_XICONS + "media-playback-stop.png"), + new ImageIcon(Icon.SCILAB_XICONS + "go-down.png"), + new ImageIcon(Icon.SCILAB_XICONS + "list-remove.png") + }; + JButton controls[] = { + new JButton(icons[0]), + new JButton(icons[1]), + new JButton(icons[2]), + new JButton(icons[3]), + new JButton(icons[4]) + }; + boolean openMask[] = { + true, + true, + true, + true, + true + }; + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Table(final Node peer) { + super(peer); + model = new Model(peer); + table = new JTable(model); + + table.getSelectionModel().addListSelectionListener(this); + table.getTableHeader().setReorderingAllowed(false); + table.setDragEnabled(false); + setupOpenMask(peer); + setupControls(peer); + + column = XCommonManager.getAttribute(peer , "column"); + + if (XCommonManager.getAttribute(peer , "mode").equals("select")) { + table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + } + + if (XCommonManager.getAttribute(peer , "mode").equals("cell")) { + table.setCellSelectionEnabled(true); + table.setColumnSelectionAllowed(false); + table.setRowSelectionAllowed(true); + } + //checkContent(); + scrollPane = new JScrollPane(table); + this.add(scrollPane); + } + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String[] actuators = {"item"}; + return actuators; + } + + public void setupOpenMask(Node peer) { + if (XCommonManager.getAttribute(peer , "location").equals("fixed")) { + openMask[1] = false; + } else { + openMask[1] = model.getRowCount() > 1; + } + if (XCommonManager.getAttribute(peer , "mode").equals("select")) { + openMask[2] = false; + } + if (XCommonManager.getAttribute(peer , "location").equals("fixed")) { + openMask[3] = false; + } else { + openMask[3] = model.getRowCount() > 1; + } + openMask[4] = model.getRowCount() != 0; + } + + public void setupControls(Node peer) { + if (XCommonManager.getAttribute(peer , "size").equals("dynamic")) { + JPanel panel = new JPanel(new GridLayout(5, 1)); + for (int i = 0; i < controls.length; i++) { + panel.add(controls[i]); + controls[i].addActionListener((ActionListener) this); + controls[i].setEnabled(false); + } + if (model.getRowCount() == 0) { + controls[0].setEnabled(true); + } + this.add(panel, BorderLayout.EAST); + } + } + + public void openControls() { + for (int i = 0; i < controls.length; i++) { + controls[i].setEnabled(openMask[i]); + } + } + + @Override + public void actionPerformed(ActionEvent e) { + int id; + JButton src = (JButton) e.getSource(); + for ( id = 0; id < controls.length; id++) { + if (controls[id] == src) { + break; + } + } + switch (id) { + case 0: + // Add new row + if (actionListener != null) { + ActionEvent transmit = new ActionEvent(this, 0, "tableAdd", e.getWhen(), 0); + actionListener.actionPerformed(transmit); + } + break; + case 1: + // Move row upper + break; + case 2: + table.getSelectionModel().clearSelection(); + for (int i = 0; i < controls.length; i++) { + controls[i].setEnabled(false); + } + break; + case 3: + break; + case 4: + // Delete row + System.out.println("[DEBUG] calling actionPerformed(deleteRow)"); + if (actionListener != null) { + ActionEvent transmit = new ActionEvent(this, 0, "tableDel", e.getWhen(), 0); + actionListener.actionPerformed(transmit); + } + break; + } + } + //end Dynamic_controller + + private final class CustomTableCellRenderer extends DefaultTableCellRenderer { + public Component getTableCellRendererComponent (JTable table, + Object obj, boolean isSelected, boolean hasFocus, int row, int column) { + Component cell = super.getTableCellRendererComponent(table, obj, isSelected, hasFocus, row, column); + if (obj instanceof java.awt.Color) { + cell.setBackground((java.awt.Color) obj); + cell.setForeground((java.awt.Color) obj); + } + + return cell; + } + } + + public void addTableModelListener(TableModelListener listener) { + model.addTableModelListener(listener); + addActionListener((ActionListener) listener); + } + + @SuppressWarnings("unused") + private void checkContent() { + for (int j = 0; j < model.getColumnCount(); j++) { + System.out.print(" " + model.getColumnName(j)); + } + System.out.print("\n"); + if (model.getRowCount() == 0) { + System.out.println("-- no tableRow items!"); + } + for (int i = 0; i < model.getRowCount(); i++) { + for (int j = 0; j < model.getColumnCount(); j++) { + System.out.print(" " + model.getValueAt(i, j)); + } + System.out.print("\n"); + } + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public final void refresh(final Node peer) { + model.setNodeList(peer.getChildNodes()); + String item = XCommonManager.getAttribute(peer , "item", "-1"); + setupOpenMask(peer); + if (!item.equals(item())) { + item(item); + } + for (int j = 0; j < model.getColumnCount(); j++) { + table.getColumnModel().getColumn(j).setCellRenderer(new CustomTableCellRenderer()); + } + repaint(); + } + + /** Row selection management. + * + */ + private ActionListener actionListener = null; + + /** Actual response read by the listener. + * + * @return the chosen value. + */ + public final Object choose() { + if (! column.equals(XCommonManager.NAV)) { + int row = table.getSelectedRow(); + Node record = model.getRowRecord(row); + String value = XCommonManager.getAttribute(record , column); + return value; + } + return item(); + } + + /** Registration of a single listener. + * @param listener for the unique actionListener. + */ + public final void addActionListener(final ActionListener listener) { + actionListener = listener; + } + + boolean externalChange; + + public void valueChanged(ListSelectionEvent e) { + //table.valueChanged(e); + if (externalChange && !e.getValueIsAdjusting()) { + openControls(); + if (actionListener != null) { + ActionEvent transmit = new ActionEvent(this, 0, "tableSelect", System.currentTimeMillis(), 0); + actionListener.actionPerformed(transmit); + } + } + } + + /** Sensor for 'item' attribute. + * + * @return the attribute value. + */ + public final String item() { + return "" + (table.getSelectedRow() + 1); + } + + /** Actuator for 'item' attribute. + * + * @param text : the attribute value. + */ + public final void item(final String item) { + int selectedRow = Integer.parseInt(item); + externalChange = false; + if ((selectedRow != -1) && (selectedRow != (table.getSelectedRow() + 1))) { + table.setRowSelectionInterval(selectedRow - 1, selectedRow - 1); + openControls(); + } + externalChange = true; + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "Table ..."; + return signature; + } + + /** Enrich action description with event and model information. + * + * @param event embeds the description of interaction in view + * @param action embeds the description of interaction in model + */ + public static void processModelEvent(TableModelEvent event, Node [] actions) { + Model src = (Model) event.getSource(); + for (int i = 0; i < actions.length; i++) { + Element element = (Element) actions[i]; + int row = event.getFirstRow(); + int col = event.getColumn(); + String value = src.getValueAt(row, col).toString(); + String attr = src.getColumnAttr(col); + String context = element.getAttribute("context"); + element.setAttribute("set", attr); + element.setAttribute("value", value); + // subtle reuse of the 'set' behavior! + element.setAttribute("context", context + (row + 1) + "/"); + } + } + +} + +/** Scans DOM nodes and translate it into table model. + * + * @author gradit + * + */ +class Model extends AbstractTableModel { + + /** Serialization ID. + * + */ + private static final long serialVersionUID = -4786321481195930071L; + + /** Data source. + * + */ + private NodeList nodelist; + private NodeList prevC, prevR; + private int rows; + private int cols; + + public Model(Node peer) { + setNodeList(peer.getChildNodes()); + } + + /** Set a new root for value scanning. + * + * @param input is the data source + */ + public void setNodeList(final NodeList input) { + nodelist = input; + } + + @Override + public int getColumnCount() { + if (nodelist != prevC) { + cols = 0; + for (int i = 0; i < nodelist.getLength(); i++) { + Node node = nodelist.item(i); + if (node.getNodeName().equals("tableCol")) { + cols++; + } + } + prevC = nodelist; + } + + return cols; + } + + @Override + public int getRowCount() { + if (nodelist != prevR) { + rows = 0; + for (int i = 0; i < nodelist.getLength(); i++) { + Node node = nodelist.item(i); + if (node.getNodeName().equals("tableRow")) { + rows++; + } + } + prevR = nodelist; + } + + return rows; + } + + /** browse DOM model. + * + * @return tablePrototype DOM node + */ + public Node getPrototypeRecord() { + for (int i = 0; i < nodelist.getLength(); i++) { + Node node = nodelist.item(i); + if (node.getNodeName().equals("tablePrototype")) { + return node; + } + } + return null; + } + + /** browse DOM model. + * + * @param col is the column identifier + * @return DOM for column + */ + public Node getColumnRecord(final int col) { + int count = col; + for (int i = 0; i < nodelist.getLength(); i++) { + Node node = nodelist.item(i); + if (node.getNodeName().equals("tableCol")) { + if (count == 0) { + return node; + } + count--; + } + } + return null; + } + + /** browse DOM model. + * + * @param row is the row identifier + * @return DOM for row + */ + public Node getRowRecord(final int row) { + int count = row; + for (int i = 0; i < nodelist.getLength(); i++) { + Node node = nodelist.item(i); + if (node.getNodeName().equals("tableRow")) { + if (count == 0) { + return node; + } + count--; + } + } + return null; + } + + /** browse DOM model. + * + * @param col is the column identifier + * @return attribute name for column. + */ + public String getColumnAttr(final int col) { + Node record = getColumnRecord(col); + if (record != null) { + return XCommonManager.getAttribute(record , "attr"); + } + return XCommonManager.NAV; + } + + @Override + public String getColumnName(final int col) { + Node record = getColumnRecord(col); + if (record != null) { + return XCommonManager.getAttribute(record , "title"); + } + return XCommonManager.NAV; + } + + @Override + public Object getValueAt(final int row, final int col) { + String attr = getColumnAttr(col); + Node record = getRowRecord(row); + String value = XCommonManager.getAttribute(record , attr); + if (value.startsWith("#")) { + return XCommonManager.getColor(value); + } + return value; + } + + @Override + public void setValueAt(final Object value, final int row, final int col) { + // temporary storage of value + String attr = getColumnAttr(col); + Element record = (Element) getRowRecord(row); + record.setAttribute(attr, value.toString()); + // event firing + TableModelEvent event = new TableModelEvent(this, row, row, col); + fireTableChanged(event); + return; + } + + @Override + public boolean isCellEditable(final int row, final int col) { + Node record = getColumnRecord(col); + String value = XCommonManager.getAttribute( + record , "editable", "false"); + return value == "true"; + } + +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/TextArea.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/TextArea.java new file mode 100755 index 000000000..db7827e08 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/TextArea.java @@ -0,0 +1,260 @@ +/* + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.regex.Pattern; + +import javax.swing.BorderFactory; +import javax.swing.JScrollBar; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.ScrollPaneConstants; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; + +import org.w3c.dom.Node; + +/** + * Implementation of a TextArea. + * + * @author Calixte DENIZET + * + */ +public class TextArea extends Panel implements XComponent, XChooser, DocumentListener { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = -7007541669965737408L; + + private JTextArea textarea; + private JScrollPane scrollPane; + private ActionListener actionListener; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {"enable", "text", "columns", "rows", "editable", "scroll"}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public TextArea(final Node peer) { + super(peer); + textarea = new JTextArea(); + textarea.setBorder(BorderFactory.createLineBorder(Color.GRAY)); + scrollPane = new JScrollPane(textarea); + add(scrollPane); + textarea.setFocusable(true); + textarea.setColumns(10); + refresh(peer); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public final void refresh(final Node peer) { + String text = XCommonManager.getAttribute(peer, "text"); + String columns = XCommonManager.getAttribute(peer, "columns"); + String rows = XCommonManager.getAttribute(peer, "rows"); + String editable = XCommonManager.getAttribute(peer, "editable"); + String scroll = XCommonManager.getAttribute(peer, "scroll"); + + if (!text.equals(text())) { + text(text); + } + + if (!columns.equals(columns())) { + columns(columns); + } + + if (!rows.equals(rows())) { + rows(rows); + } + + if (!editable.equals(editable())) { + editable(editable); + } + + if (!scroll.equals(scroll())) { + scroll(scroll); + } + + boolean enable = XConfigManager.getBoolean(peer, "enable", true); + textarea.setEnabled(enable); + JScrollBar bar = scrollPane.getVerticalScrollBar(); + if (bar != null) { + bar.setEnabled(enable); + } + + bar = scrollPane.getHorizontalScrollBar(); + if (bar != null) { + bar.setEnabled(enable); + } + } + + /** + * {@inheritDoc} + */ + public void changedUpdate(DocumentEvent e) { } + + /** + * {@inheritDoc} + */ + public void insertUpdate(DocumentEvent e) { + update(); + } + + /** + * {@inheritDoc} + */ + public void removeUpdate(DocumentEvent e) { + update(); + } + + private void update() { + if (actionListener != null) { + ActionEvent transmit = new ActionEvent(this, 0, "TextArea change", System.currentTimeMillis(), 0); + actionListener.actionPerformed(transmit); + } + } + + /** Sensor for 'text' attribute. + * + * @return the attribute value. + */ + public final String text() { + return textarea.getText(); + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void columns(final String columns) { + if (!columns.equals(XCommonManager.NAV)) { + int jColumns = Integer.parseInt(columns); + textarea.setColumns(jColumns); + } + } + + /** Sensor for 'columns' attribute. + * + * @return the attribute value. + */ + public final String columns() { + return Integer.toString(textarea.getColumns()); + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void rows(final String rows) { + if (!rows.equals(XCommonManager.NAV)) { + int jRows = Integer.parseInt(rows); + textarea.setRows(jRows); + } + } + + /** Sensor for 'columns' attribute. + * + * @return the attribute value. + */ + public final String rows() { + return Integer.toString(textarea.getRows()); + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void editable(final String editable) { + textarea.setEditable(editable.equalsIgnoreCase("true")); + } + + /** Sensor for 'columns' attribute. + * + * @return the attribute value. + */ + public final String editable() { + return Boolean.toString(textarea.isEditable()); + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void scroll(final String scroll) { + scrollPane.setVerticalScrollBarPolicy(scroll.equalsIgnoreCase("true") ? ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED : ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + scrollPane.setHorizontalScrollBarPolicy(scroll.equalsIgnoreCase("true") ? ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED : ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + } + + /** Sensor for 'columns' attribute. + * + * @return the attribute value. + */ + public final String scroll() { + return Boolean.toString(scrollPane.getVerticalScrollBarPolicy() == ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + } + + /** Actuator for 'text' attribute. + * + * @param text : the attribute value. + */ + public final void text(final String text) { + textarea.setText(text); + } + + public void addActionListener(ActionListener actionListener) { + this.actionListener = actionListener; + } + + public void addDocumentListener(DocumentListener listener) { + textarea.getDocument().addDocumentListener(listener); + } + + /** Actual response read by the listener. + * + * @return response read by the listener. + */ + public final Object choose() { + return text(); + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "TextArea"; + if (!text().equals(XCommonManager.NAV)) { + signature += " text='" + text() + "'"; + } + return signature; + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Title.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Title.java new file mode 100755 index 000000000..8e67bb056 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Title.java @@ -0,0 +1,105 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; + +import javax.swing.BorderFactory; +import javax.swing.border.TitledBorder; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.UIManager; + +import org.w3c.dom.Node; + +import org.scilab.modules.preferences.XComponent; +import org.scilab.modules.preferences.XConfigManager; + +/** + * Implementation of Title compliant with extended management. + * + * @author Pierre GRADIT + * + */ +@SuppressWarnings(value = { "serial" }) +public class Title extends Panel implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = 6183280975436648612L; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public String[] actuators() { + return new String[] {}; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public Title(final Node peer) { + super(peer); + String text = XConfigManager.getAttribute(peer, "text"); + TitledBorder title = new TitledBorder(text) { + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + super.paintBorder(c, g, x, y - TitledBorder.EDGE_SPACING - 1, width, height + 2 * TitledBorder.EDGE_SPACING + 2); + } + }; + + Font font = title.getTitleFont(); + if (font == null) { + font = UIManager.getDefaults().getFont("TitledBorder.font"); + if (font == null) { + JLabel label = new JLabel("a"); + font = label.getFont(); + if (font == null) { + font = new Font("Sans Serif", Font.PLAIN, 10); + } + } + } + title.setTitleFont(font.deriveFont(Font.BOLD)); + setBorder(title); + XConfigManager.setDimension(this, peer); + + String background = XConfigManager.getAttribute(peer, "background"); + if (!(background.equals(XConfigManager.NAV))) { + Color color = XConfigManager.getColor(background); + setOpaque(true); + setBackground(color); + } + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + return "Title"; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/Tree.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Tree.java new file mode 100755 index 000000000..06418675f --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/Tree.java @@ -0,0 +1,318 @@ +/* + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.event.TreeModelListener; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.scilab.modules.preferences.XChooser; +import org.scilab.modules.preferences.XCommonManager; +import org.scilab.modules.preferences.XComponent; + +/** + * Implementation of Select compliant with extended management. + * + * @author Pierre GRADIT + */ +public class Tree extends Panel implements XComponent, XChooser, TreeSelectionListener { + + /** + * Universal identifier for serialization. + */ + private static final long serialVersionUID = -6127289363733321914L; + + private ActionListener actionListener = null; + private XTreeModel model; + private JTree tree; + private boolean dontChange = false; + + /** + * Constructor. + * @param peer: associated view DOM node. + */ + public Tree(final Node peer) { + super(peer); + model = new XTreeModel(peer); + tree = new JTree(); + tree.setModel(model); + tree.getSelectionModel().addTreeSelectionListener(this); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + tree.setRootVisible(false); + tree.setShowsRootHandles(true); + tree.setExpandsSelectedPaths(true); + + // Under Windows the directory icon is used: bad.... + DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); + renderer.setLeafIcon(null); + renderer.setClosedIcon(null); + renderer.setOpenIcon(null); + + JScrollPane scrollPane = new JScrollPane(tree); + this.add(scrollPane); + } + + /** + * Define the set of actuators. + * @return array of actuator names. + */ + public final String[] actuators() { + String[] actuators = {"item"}; + return actuators; + } + + /** + * Refresh the component by the use of actuators. + * @param peer the corresponding view DOM node + */ + public final void refresh(final Node peer) { + model.setRoot(peer); + String path = XCommonManager.getAttribute(XCommonManager.getElementByContext("/"), "path", "/1"); + + if (!path.equals(path())) { + path(path); + } + } + + /** + * Actual response read by the listener. + * @return the chosen value. + */ + public final Object choose() { + return path(); + } + + /** + * Registration of a single listener. + * @param listener for the unique actionListener. + */ + public final void addActionListener(final ActionListener listener) { + actionListener = listener; + } + + /** + * {@inheritDoc} + */ + public void valueChanged(TreeSelectionEvent e) { + if (actionListener != null && !dontChange) { + ActionEvent transmit = new ActionEvent(this, 0, "actionPerformed", e.hashCode(), 0); + actionListener.actionPerformed(transmit); + } + } + + /** + * Sensor for 'path' attribute. + * @return the attribute value. + */ + public final String path() { + TreePath tp = tree.getSelectionPath(); + if (tp != null) { + StringBuilder path = new StringBuilder(); + Object[] selection = tp.getPath(); + XAdapterNode prev = (XAdapterNode) selection[0]; + for (int i = 1; i < selection.length; i++) { + XAdapterNode next = (XAdapterNode) selection[i]; + int index = prev.getIndexOfChild(next) + 1; + if (i == 1) { + path.append(Integer.toString(index)); + } else { + // case of bodies... + path.append(Integer.toString(index + 1)); + } + + path.append("/"); + prev = next; + } + + return path.toString(); + } + + return "-1"; + } + + /** + * Actuator for 'item' attribute. + * @param text : the attribute value. + */ + public final void path(final String item) { + String[] ids = item.split("/"); + int index = 0; + XAdapterNode node = (XAdapterNode) tree.getModel().getRoot(); + for (int i = 0; i < ids.length; i++) { + try { + index += Integer.parseInt(ids[i]) - 1; + node = node.getChild(index); + if (i < ids.length - 1) { + tree.expandRow(index); + } else { + dontChange = true; + tree.setSelectionRow(index); + dontChange = false; + } + } catch (NumberFormatException e) { + dontChange = true; + tree.setSelectionRow(0); + dontChange = false; + break; + } + } + } + + /** + * Developer serialization method. + * @return equivalent signature. + */ + public final String toString() { + return "Tree ..."; + } +} + +class XAdapterNode { + + Node peer; + + public XAdapterNode(Node node) { + peer = node; + } + + public Node getPeer() { + return peer; + } + + public String toString() { + return XCommonManager.getAttribute(peer, "name", ""); + } + + public String content() { + return peer.getNodeName(); + } + + public XAdapterNode getChild(int index) { + NodeList nodelist = peer.getChildNodes(); + int count = index; + final int size = nodelist.getLength(); + for (int i = 0; i < size; i++) { + Node node = nodelist.item(i); + if (node.getNodeName().startsWith("#") || node.getNodeName().equals("actionPerformed")) { + continue; + } + if (count == 0) { + return new XAdapterNode(node); + } + count--; + } + return null; //unreachable statement + } + + public int getChildCount() { + NodeList nodelist = peer.getChildNodes(); + int count = 0; + final int size = nodelist.getLength(); + for (int i = 0; i < size; i++) { + Node node = nodelist.item(i); + if (node.getNodeName().startsWith("#") || node.getNodeName().equals("actionPerformed")) { + continue; + } + count++; + } + return count; + } + + public int getIndexOfChild(XAdapterNode child) { + NodeList nodelist = peer.getChildNodes(); + int count = 0; + final int size = nodelist.getLength(); + for (int i = 0; i < size; i++) { + Node node = nodelist.item(i); + if (node.getNodeName().startsWith("#") || node.getNodeName().equals("actionPerformed")) { + continue; + } + if (child.peer == node) { + return count; + } + count++; + } + return -1; //unreachable statement + } +} + +/** + * Scans DOM nodes and translate it into tree model. + * @author Pierre GRADIT + * + */ +class XTreeModel implements TreeModel { + + /** + * Serialization ID. + */ + private static final long serialVersionUID = -4786321481195930071L; + + /** + * Data source. + */ + private XAdapterNode root; + private Node peer; + + public XTreeModel(Node peer) { + setRoot(peer); + } + + public void setRoot(final Node input) { + if (input != peer) { + peer = input; + root = new XAdapterNode(input); + } + } + + public Object getChild(Object node, int index) { + return ((XAdapterNode) node).getChild(index); + } + + public int getChildCount(Object node) { + return ((XAdapterNode) node).getChildCount(); + } + + public int getIndexOfChild(Object node, Object other) { + return ((XAdapterNode) node).getIndexOfChild((XAdapterNode) other); + } + + public Object getRoot() { + return root; + } + + public boolean isLeaf(Object node) { + return ((XAdapterNode) node).getChildCount() == 0; + } + + public void valueForPathChanged(TreePath arg0, Object arg1) { } + + public void addTreeModelListener(TreeModelListener arg0) { } + + public void removeTreeModelListener(TreeModelListener arg0) { } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/VBox.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/VBox.java new file mode 100755 index 000000000..1b7529fd1 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/VBox.java @@ -0,0 +1,107 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences.Component; + +import org.scilab.modules.preferences.XComponent; + +import javax.swing.BoxLayout; +import javax.swing.JComponent; +import javax.swing.JPanel; +import org.w3c.dom.Node; +import org.scilab.modules.preferences.XConfigManager; + +import java.awt.Color; +import java.awt.Component; + +/** Implementation of Panel compliant with extended management. +* +* @author Pierre GRADIT +* +*/ +public class VBox extends Panel implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = 3462302313959678932L; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public VBox(final Node peer) { + super(peer); + BoxLayout box = new BoxLayout(this, BoxLayout.PAGE_AXIS); + setLayout(box); + refresh(peer); + } + + /** Overloaded add method to embed grid layout. + * + */ + public void add(Component child, Object constraints, int index) { + if (child instanceof JComponent) { + ((JComponent) child).setAlignmentX(LEFT_ALIGNMENT); + ((JComponent)child).setAlignmentY(TOP_ALIGNMENT); + } + super.add(child, constraints, index); + } + + /** Overloaded add method to embed grid layout. + * + */ + public void add(Component child, Object constraints) { + if (child instanceof JComponent) { + ((JComponent) child).setAlignmentX(LEFT_ALIGNMENT); + ((JComponent) child).setAlignmentY(TOP_ALIGNMENT); + } + super.add(child, constraints); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + String background = XConfigManager.getAttribute(peer , "background"); + if (background.equals(XConfigManager.NAV)) { + setOpaque(false); + setBackground(null); + } else { + Color color = XConfigManager.getColor(background); + setOpaque(true); + setBackground(color); + } + } + + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "VBox"; + + return signature; + } +} + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/Component/XCosPreview.java b/modules/preferences/src/java/org/scilab/modules/preferences/Component/XCosPreview.java new file mode 100755 index 000000000..cbe1e0700 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/Component/XCosPreview.java @@ -0,0 +1,75 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ +package org.scilab.modules.preferences.Component; + +import javax.swing.JLabel; + +import org.scilab.modules.preferences.XComponent; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class XCosPreview extends JLabel implements XComponent { + + /** Universal identifier for serialization. + * + */ + private static final long serialVersionUID = 3462302313959678932L; + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + public final String [] actuators() { + String [] actuators = {}; + return actuators; + } + + /** Constructor. + * + * @param peer : associated view DOM node. + */ + public XCosPreview(final Node peer) { + super(); + } + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + public void refresh(final Node peer) { + Node root = peer.getFirstChild().getFirstChild(); + NodeList nodeList = root.getChildNodes(); + String portSize = "["; + + for (int i = 0 ; i < nodeList.getLength() ; ++i) { + Node cur = nodeList.item(i); + portSize = portSize + cur.getNodeName(); + portSize = portSize + "="; + portSize = portSize + cur.getNodeValue(); + portSize = portSize + ";"; + + } + portSize = portSize + "]"; + setText(portSize); + } + + /** Developer serialization method. + * + * @return equivalent signature. + */ + public final String toString() { + String signature = "BlockPreview"; + + return signature; + } +}
\ No newline at end of file diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/ComponentFactory.java b/modules/preferences/src/java/org/scilab/modules/preferences/ComponentFactory.java new file mode 100755 index 000000000..41834f8de --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/ComponentFactory.java @@ -0,0 +1,187 @@ +/* + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +import org.w3c.dom.Node; + +import org.scilab.modules.commons.ScilabCommonsUtils; +import org.scilab.modules.preferences.Component.Scroll; + +/** + * Component factory + * + * @author Calixte DENIZET + * + */ +class ComponentFactory { + + private static final String X_PACKAGE = "org.scilab.modules.preferences.Component."; + private static final int SPACE = 5; + private static final Map < String, Constructor <? extends Component >> cache = new HashMap < String, Constructor <? extends Component >> (); + private static final Map<String, MyAction> actions = new HashMap<String, MyAction>(); + + static { + actions.put("Scroll", new MyAction() { + 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()); + } + }); + actions.put("VSpace", new MyAction() { + 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, "width", SPACE)); + } + }); + actions.put("Glue", new MyAction() { + public Component getComponent(final Node node) { + return Box.createGlue(); + } + }); + } + + public static final Component getComponent(final Node node) { + Component component; + String tag = node.getNodeName(); + MyAction action = actions.get(tag); + if (action != null) { + component = action.getComponent(node); + return component; + } + + Constructor <? extends Component > constructor = cache.get(tag); + if (constructor == null) { + if ("PreviewCode".equals(tag)) { + ScilabCommonsUtils.loadOnUse("SciNotes"); + } + + Class <? extends Component > componentClass; + try { + componentClass = Class.forName(X_PACKAGE + tag).asSubclass(Component.class); + } 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}; + constructor = componentClass.getConstructor(parameter); + } catch (NoSuchMethodException e) { + System.err.println("NoSuchMethodException:" + e); + return new XStub(node, "NoSuchMethodException"); + } catch (SecurityException e) { + // Declare failure due to constructor rights (it must be public) + System.err.println("SecurityException:" + e); + return new XStub(node, "SecurityException"); + } + + cache.put(tag, constructor); + } + + try { + component = (Component) constructor.newInstance(new Object[] {node}); + } catch (InstantiationException e) { + System.err.println("InstantiationException:" + e); + return new XStub(node, "InstantiationException"); + } catch (IllegalAccessException e) { + System.err.println("IllegalAccessException:" + e); + return new XStub(node, "IllegalAccessException"); + } catch (IllegalArgumentException e) { + System.err.println("IllegalArgumentException:" + e); + return new XStub(node, "IllegalArgumentException"); + } catch (InvocationTargetException e) { + System.err.println("InvocationTargetException:" + e.getTargetException()); + e.getTargetException().printStackTrace(); + return new XStub(node, "InvocationTargetException"); + } + + return component; + } + + private static interface MyAction { + Component getComponent(final Node node); + } + + /** + * Graphical indication of what goes wrong in buildPeerFor(node). + */ + private static class XStub extends JPanel { + + /** + * Serialization id. + */ + private static final long serialVersionUID = -6540983459186007758L; + + /** + * Default height. + */ + private static final int D_HEIGHT = 50; + + /** + * Default width. + */ + private static final int D_WIDTH = 100; + + /** Constructor. + * @param tag : class name source of the error + * @param cause : description of the error + * + */ + public XStub(final Node node, final String cause) { + super(); + Border red = BorderFactory.createLineBorder(Color.RED); + TitledBorder title = BorderFactory.createTitledBorder(red, node.getNodeName() + " " + cause); + Dimension dimension = new Dimension(D_WIDTH, D_HEIGHT); + setPreferredSize(dimension); + setOpaque(false); + XConfigManager.setDimension(this, node); + + title.setTitleColor(Color.RED); + setBorder(title); + setLayout(new FlowLayout()); + } + + /** + * Output method. + * @return the string representation + */ + public String toString() { + return "STUB"; + } + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/ScilabPreferences.java b/modules/preferences/src/java/org/scilab/modules/preferences/ScilabPreferences.java new file mode 100755 index 000000000..95cc7c0f9 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/ScilabPreferences.java @@ -0,0 +1,130 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - DIGITEO - 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.1-en.txt + * + */ + +package org.scilab.modules.preferences; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.SwingUtilities; + +import org.scilab.modules.localization.Messages; + +/** + * @author Calixte DENIZET + */ +public class ScilabPreferences { + + private static Map<String, ToolboxInfos> tbxs = new HashMap<String, ToolboxInfos>(); + + /** + * 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(initialPath); + } + }); + } + + /** + * @param name the toolbox name + * @param path the toolbox path + * @param prefFile the toolbox preference file path + */ + public static void addToolboxInfos(String name, String path, String prefFile) throws Exception { + File f = new File(path); + if (!f.exists()) { + throw new Exception(Messages.gettext("Invalid path:") + " " + path + "."); + } + f = new File(prefFile); + if (!f.exists()) { + throw new Exception(Messages.gettext("Invalid preferences file:") + " " + prefFile + "."); + } + tbxs.put(path, new ToolboxInfos(name, path, prefFile)); + } + + /** + * @return a list of the toolboxes infos + */ + public static List<ToolboxInfos> getToolboxesInfos() { + return new ArrayList<ToolboxInfos>(tbxs.values()); + } + + /** + * @param path the toolbox to remove + */ + public static void removeToolboxInfos(String path) { + tbxs.remove(path); + } + + /** + * Toolbox infos + */ + public static class ToolboxInfos { + + private String name; + private String path; + private String prefFile; + + /** + * Default constructor + * @param name the toolbox name + * @param path the toolbox path + * @param prefFile the toolbox preference file path + */ + public ToolboxInfos(String name, String path, String prefFile) { + this.name = name; + this.path = path; + this.prefFile = prefFile; + } + + /** + * @return the toolbox name + */ + public String getName() { + return name; + } + + /** + * @return the toolbox path + */ + public String getPath() { + return path; + } + + /** + * @return the toolbox preference file path + */ + public String getPrefFile() { + return prefFile; + } + + /** + * {@inheritDoc} + */ + public String toString() { + return "Toolbox: " + name + "\nPath: " + path + "\nPreference file: " + prefFile; + } + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/XChooser.java b/modules/preferences/src/java/org/scilab/modules/preferences/XChooser.java new file mode 100755 index 000000000..141217daa --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/XChooser.java @@ -0,0 +1,39 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences; + +import java.awt.event.ActionListener; + +/** XChooser implements an XComponent giving a response. + * + * @author Pierre GRADIT + * + **/ +public interface XChooser { + + + /** Subscription for an action listener. + * + * @param actionListener : subscribing listener. + */ + void addActionListener(ActionListener actionListener); + + /** Actual response read by the listener. + * + * @return response read by the listener. + */ + Object choose(); + +} + + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/XCommonManager.java b/modules/preferences/src/java/org/scilab/modules/preferences/XCommonManager.java new file mode 100755 index 000000000..f2ccfd319 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/XCommonManager.java @@ -0,0 +1,929 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - INRIA - Vincent COUVERT + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; +import java.io.File; +import java.io.FilenameFilter; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.StringReader; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Stack; +import java.util.StringTokenizer; + +import javax.swing.JDialog; +import javax.swing.SwingUtilities; +import javax.swing.border.Border; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import org.scilab.modules.commons.OS; +import org.scilab.modules.commons.xml.ScilabDocumentBuilderFactory; +import org.scilab.modules.commons.xml.ScilabTransformerFactory; +import org.scilab.modules.commons.xml.XConfiguration; +import org.scilab.modules.gui.console.ScilabConsole; +import org.scilab.modules.localization.Messages; +import org.scilab.modules.localization.WindowsDefaultLanguage; + +/* This class is the common ancestor to both X_manager. + */ +public abstract class XCommonManager { + + /** XConfiguration management verbosity.*/ + public static final boolean performances = true; + + /** XConfiguration management verbosity.*/ + public static final boolean differential = true; + + /** Message for read error.*/ + protected static final String ERROR_READ = "Could not load file: "; + + /** Message for write error.*/ + protected static final String ERROR_WRITE = "Could not save file: "; + + /** Buffer size.*/ + protected static final int BUFSIZE = 1024; + + /** Main dialog.*/ + protected static JDialog dialog; + + /** DOM Document.*/ + protected static Document document; + + /** DOM Document.*/ + protected static String documentAddress; + + /** Up-to-date flag.*/ + protected static boolean updated = false; + + /** Top level DOM Node.*/ + protected static Node topDOM; + + /** Top level Swing container.*/ + protected static Container topSwing; + + /** Container-Sentinel correspondence.*/ + protected static Map<Component, XSentinel> correspondance; + + /** Last visitor.*/ + protected static XUpdateVisitor visitor; + + /** Last current time.*/ + protected static long time = System.currentTimeMillis(); + + /** + * XSL Transformer factory. + */ + protected static TransformerFactory factory; + + /** + * XML Document builder factory. + */ + protected static DocumentBuilderFactory builder = ScilabDocumentBuilderFactory.newInstance(); + + /** + * XSL Transformer. + */ + protected static Transformer transformer = null; + + private static final String SCI = System.getenv("SCI"); + + /** Scilab configuration file.*/ + private static final String SCILAB_CONFIG_FILE = SCI + "/modules/preferences/etc/XConfiguration.xml"; + + private static String XSLCODE; + + 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); + } + + if (f.exists() && f.canRead()) { + return new StreamSource(f); + } + } catch (Exception e) { + System.out.println(e); + } + + throw new TransformerException("Cannot find the file " + href + "::" + base); + } + }); + } + + /** + * Monitor time between calls. + */ + public static void printTimeStamp(final String msg) { + long nextTime = System.currentTimeMillis(); + long deltaTime = nextTime - time; + if (performances) { + System.out.println((msg.startsWith("*") ? "" : " | ") + msg + " in " + deltaTime + " ms."); + } + time = nextTime; + } + + /** Launch swing hierarchy update. + * + * @return whether XSL return a node or not. + */ + public static boolean refreshDisplay() { + topDOM = generateViewDOM().getNode().getFirstChild();//System.out.println(XConfiguration.dumpNode(generateViewDOM().getNode())); + if (topDOM == null) { + System.err.println("XSL does not give a node!"); + return false; + } + + // Refresh correspondence + // TODO top layout changes + visitor = new XUpdateVisitor(correspondance); + visitor.visit(topSwing, topDOM); + boolean changed = setDimension(dialog, topDOM); + if (changed) { + dialog.pack(); + } + + return true; + } + + /** + * Horizontal space between parent and child in String representations. + */ + public static final String INCREMENT = " "; + + /** + * Compute recursive string representation of DOM view tree. + * @param node : current node + * @param indent : current indentation + * @return node representation + * + */ + private static String viewDOM(final Node node, final String indent) { + String signature = indent; + if (node.hasAttributes()) { + signature += XSentinel.signature(node, new String[0]); + } else { + String single = node.getNodeName() + ": " + node.getNodeValue(); + signature += single.replaceAll("[ \t\n]+", " "); + } + signature += "\n"; + NodeList nodelist = node.getChildNodes(); + for (int i = 0; i < nodelist.getLength(); i++) { + Node item = nodelist.item(i); + signature += viewDOM(item, indent + INCREMENT); + } + + return signature; + } + + /** + * Compute top-level string representation of DOM view tree. + * @return document representation + */ + protected static String viewDOM() { + return viewDOM(topDOM, ""); + } + + /** + * Compute recursive string representation of Swing tree. + * @param component : current component + * @param indent : current indentation + * @return component representation + * + */ + private static String swingComposite(final Component component, final String indent) { + String signature = indent; + signature += component.toString() + "\n"; + if (component instanceof Container) { + Container container = (Container) component; + Component [] components = container.getComponents(); + for (int i = 0; i < components.length; i++) { + Component child = components[i]; + signature += swingComposite(child, indent + INCREMENT); + } + } + return signature; + } + + /** + * Compute top-level string representation of swing composite. + * @return Graphical interface representation + */ + protected static String swingComposite() { + return swingComposite(topSwing, ""); + } + + private 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(); + } + }); + + for (File module : modules) { + File etc = new File(module, "/etc/"); + if (etc.exists() && etc.isDirectory()) { + list.add(etc); + } + } + + return list; + } + + /** + * Create a XSL string in using the XConfiguration-*.xsl found in SCI/modules/MODULE_NAME/etc/ + * @return the buit XSL string. + */ + protected static String createXSLFile() { + if (XSLCODE == null) { + List<File> etcs = XConfiguration.getEtcDir(); + + StringBuilder buffer = new StringBuilder("<?xml version='1.0' encoding='utf-8'?>\n"); + buffer.append("<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n"); + buffer.append("<xsl:param name=\"OS\"/>\n"); + buffer.append("<xsl:param name=\"SCILAB_LANGUAGE\"/>\n"); + 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"); + } + }; + + // Include standard Scilab xsl files + for (File etc : etcs) { + File[] xsls = etc.listFiles(filter); + for (File xsl : xsls) { + try { + buffer.append("<xsl:import href=\"").append(xsl.getCanonicalPath()).append("\"/>\n"); + } catch (IOException e) { + buffer.append("<xsl:import href=\"").append(xsl.getAbsolutePath()).append("\"/>\n"); + } + } + } + + // Include toolboxes xsl files + List<ScilabPreferences.ToolboxInfos> infos = ScilabPreferences.getToolboxesInfos(); + filter = new FilenameFilter() { + 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); + for (File xsl : xsls) { + try { + buffer.append("<xsl:import href=\"").append(xsl.getCanonicalPath()).append("\"/>\n"); + } catch (IOException e) { + buffer.append("<xsl:import href=\"").append(xsl.getAbsolutePath()).append("\"/>\n"); + } + } + } + + buffer.append("</xsl:stylesheet>"); + + XSLCODE = buffer.toString(); + } + + return XSLCODE; + } + + public static void invalidateXSL() { + XSLCODE = null; + } + + /** + * Load XSL as XSL Transformer. + */ + protected static void reloadTransformer(String address) { + try { + StreamSource source = new StreamSource(new StringReader(createXSLFile())); + transformer = factory.newTransformer(source); + transformer.setParameter("OS", OS.getVersionName()); + if (OS.get() == OS.WINDOWS) { + transformer.setParameter("SCILAB_LANGUAGE", WindowsDefaultLanguage.getdefaultlanguage()); + } else { + transformer.setParameter("SCILAB_LANGUAGE", ""); + } + } catch (TransformerConfigurationException e1) { + System.err.println(ERROR_READ + address); + } catch (TransformerFactoryConfigurationError e1) { + System.err.println(ERROR_READ + address); + } + } + + /** + * Generate view by application of XSL on XConfiguration file. + * @return View DOM. + */ + private static DOMResult generateViewDOM() { + DOMResult result = new DOMResult(); + DOMSource source = new DOMSource(document); + try { + transformer.transform(source, result); + } catch (TransformerException e) { + // Just highlight clear transformer output. + System.out.println("\n"); + } + return result; + } + + /** + * Identify an element with its context string. + * @see XConfiguration.xsl#context + * @param context : the context string used to catch the element. + * @return the corresponding node + */ + public static Element getElementByContext(final String context) { + String[] ids = context.split("/"); + 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) + NodeList childNodes = element.getChildNodes(); + Node node = null; + for (int j = 0; index > 0 && j < childNodes.getLength(); j++) { + node = childNodes.item(j); + if (!node.getNodeName().equals("#text") && !node.getNodeName().equals("#comment")) { + index--; + } + } + if (index == 0) { + element = (Element) node; + } else { + System.err.println("'" + context + "' out of document!"); + return null; + } + } + return element; + } + + /** + * 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). + * @return if the event is handled here + */ + protected static boolean generixEvent(final Node[] actions, final Component source) { + if (actions.length == 0) { + return false; + } + + Node action = actions[0]; + // All actions must be of the same kind. + + 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"); + 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)); + } + } + refreshDisplay(); + updated = true; + return true; + } + + if (!getAttribute(action, "insert").equals(NAV) && enable) { + for (int i = 0; i < actions.length; i++) { + action = actions[i]; + String context = getAttribute(action, "context"); + Element element = getElementByContext(context); + String insertValue = XCommonManager.getAttribute(action, "insert"); + int insert = 0; + try { + insert = Integer.decode(insertValue); + } catch (NumberFormatException e) { + XChooser chooser = (XChooser) source; + insertValue = chooser.choose().toString(); + insert = Integer.decode(insertValue) + 1; + } + Node hook = null; + NodeList nodelist = element.getChildNodes(); + for (int xi = 0; xi < nodelist.getLength(); xi++) { + Node node = nodelist.item(xi); + if (!node.getNodeName().equals("#text") && !node.getNodeName().equals("#comment")) { + if (insert == 1) { + hook = node; + break; + } + insert --; + } + } + DocumentFragment fragment = document.createDocumentFragment(); + while (action.hasChildNodes()) { + Node transferred = action.getFirstChild(); + action.removeChild(transferred); + transferred = document.importNode(transferred, true); + fragment.appendChild(transferred); + } + if (element != null) { + element.insertBefore(fragment, hook); + } + } + refreshDisplay(); + updated = true; + + return true; + } + + if (!getAttribute(action, "delete").equals(NAV) && enable) { + for (int i = 0; i < actions.length; i++) { + action = actions[i]; + String context = getAttribute(action, "context"); + Element element = getElementByContext(context); + String xDelete = XCommonManager.getAttribute(action, "delete"); + int delete = 0; + try { + delete = Integer.decode(xDelete); + } catch (NumberFormatException e) { + if (source == null) { + return false; + } + XChooser chooser = (XChooser) source; + xDelete = chooser.choose().toString(); + delete = Integer.decode(xDelete); + } + Node deleted = null; + NodeList nodelist = element.getChildNodes(); + for (int xi = 0; xi < nodelist.getLength(); xi++) { + Node node = nodelist.item(xi); + if (!node.getNodeName().equals("#text") && !node.getNodeName().equals("#comment")) { + if (delete == 1) { + deleted = node; + break; + } + delete--; + } + } + if (element != null && deleted != null) { + element.removeChild(deleted); + } + } + refreshDisplay(); + updated = true; + + return true; + } + + if (!getAttribute(action, "choose").equals(NAV) && enable) { + if (source == null) { + return false; + } + + String context = getAttribute(action, "context"); + Element element = getElementByContext(context); + + if (source instanceof XChooser) { + XChooser chooser = (XChooser) source; + Object value = chooser.choose(); + if (value != null) { + String attribute = getAttribute(action, "choose"); + if (element != null) { + if (value instanceof String[]) { + String[] values = (String[]) value; + StringTokenizer toks = new StringTokenizer(attribute, ","); + int n = Math.min(toks.countTokens(), values.length); + for (int i = 0; i < n; i++) { + String attr = toks.nextToken().trim(); + element.setAttribute(attr, values[i]); + } + } else { + element.setAttribute(attribute, value.toString()); + } + XConfiguration.addModifiedPath(getNodePath(element)); + } + refreshDisplay(); + updated = true; + } + } else { + System.err.println("@choose attribute only valid on choosers " + "(SELECT, COLOR, FILE, ENTRY,...)"); + } + return true; + } + + if (!getAttribute(action, "choose-child").equals(NAV) && enable) { + if (source == null) { + return false; + } + + int childNb = Integer.parseInt(getAttribute(action, "choose-child")) - 1; + String context = getAttribute(action, "context"); + Element element = getElementByContext(context); + NodeList list = element.getChildNodes(); + if (element == null || childNb < 0 || childNb >= list.getLength()) { + return false; + } + Node child = list.item(childNb); + + if (source instanceof XChooser) { + XChooser chooser = (XChooser) source; + Object value = chooser.choose(); + if (value != null) { + child.setTextContent(value.toString()); + XConfiguration.addModifiedPath(getNodePath(element)); + refreshDisplay(); + updated = true; + } + } else { + System.err.println("@choose-child attribute only valid on choosers " + "(SELECT, COLOR, FILE, ENTRY,...)"); + } + + return true; + } + + 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) { + String nname = n.getNodeName(); + NamedNodeMap attrs = n.getAttributes(); + if (attrs != null && attrs.getLength() != 0) { + Node attr = attrs.getNamedItem("xconf-uid"); + if (attr != null) { + nname += "[@xconf-uid=\"" + attr.getNodeValue() + "\"]"; + } + } + stack.push(nname); + 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. + */ + public static final String NAV = "\"not an value'"; + + /** + * Attribute consulting with default. + * @param node : consulted node + * @param name : attribute key + * @param value : default value + * @return the consulted value + */ + public static String getAttribute(final Node node, final String name, final String value) { + String response = getAttribute(node, name); + if (response == NAV) { + return value; + } + + return response; + } + + /** + * Attribute consulting without default. + * @param node : consulted node. + * @param name : attribute key. + * @return the consulted value (or NAV if attribute key is absent) + */ + public static String getAttribute(final Node node, final String name) { + NamedNodeMap attrs = node.getAttributes(); + if (attrs == null) { + return NAV; + } + Node attr = attrs.getNamedItem(name); + if (attr == null) { + return NAV; + } + + String response = attr.getNodeValue(); + if (response.startsWith("_(") && response.endsWith(")")) { + response = Messages.gettext(response.substring(2, response.length() - 1)); + } + + if (response.startsWith("_d(") && response.endsWith(")")) { + int iPos = response.indexOf(","); + String domain = response.substring(3, iPos).trim(); + String text = response.substring(iPos + 2, response.length() - 1).trim(); + System.out.println("domain : !" + domain + "! text : !" + text + "!"); + response = Messages.dgettext(domain, text); + } + return response; + } + + /** + * Typed attribute consulting with default. + * @param node : consulted node. + * @param name : attribute key. + * @param value : default value. + * @return the value. + */ + public static int getInt(final Node node, final String name, final int value) { + String response = getAttribute(node, name); + if (response.equals(NAV) || response.equals("")) { + return value; + } + + try { + return Integer.parseInt(response); + } catch (NumberFormatException e) { + return 0; + } + } + + /** + * Typed attribute consulting with default. + * @param node : consulted node. + * @param name : attribute key. + * @param value : default value. + * @return the value. + */ + public static double getDouble(final Node node, final String name, final double value) { + String response = getAttribute(node, name); + if (response.equals(NAV) || response.equals("")) { + return value; + } + + try { + return Double.parseDouble(response); + } catch (NumberFormatException e) { + return 0; + } + } + + /** + * Typed attribute consulting with default. + * @param node : consulted node. + * @param name : attribute key. + * @param value : default value. + * @return the value. + */ + public static boolean getBoolean(final Node node, final String name, final boolean value) { + String response = getAttribute(node, name); + if (response.equals(NAV) || response.equals("")) { + return value; + } + + return response.equalsIgnoreCase("true"); + } + + /** + * Manage color representation. + * @param source : the color. + * @return the string representation. + */ + public static String getColor(final Color source) { + if (source == null) { + return "#000000"; + } + + String hexStr = Integer.toHexString(source.getRGB()); + return "#" + hexStr.substring(2); + } + + /** + * Manage color representation. + * @param source : the string representation. + * @return the corresponding color + */ + public static Color getColor(final String source) { + return Color.decode(source); + } + + /** + * Get top level window for correct dialog opening. + * @return top-level frame. + */ + public static Frame getTopLevel() { + if (ScilabConsole.isExistingConsole()) { + Container main = (Container) ScilabConsole.getConsole().getAsSimpleConsole(); + return (Frame) SwingUtilities.getAncestorOfClass(Frame.class, main); + } + + return null; + } + + /** + * Set a dimension for a component. + * @param component : the resized component. + * @param peer : the node having the dimension information. + */ + public static boolean setDimension(final Component component, final Node peer) { + int height = XConfigManager.getInt(peer, "height", 0); + int width = XConfigManager.getInt(peer, "width", 0); + if (height > 0 && width > 0) { + Dimension old = component.getPreferredSize(); + if (old.width != width || old.height != height) { + component.setPreferredSize(new Dimension(width, height)); + return true; + } + } + + return false; + } + + /** + * Create a copy of Scilab configuration file in the user directory. + */ + public static void createUserCopy(String original, String copy) { + File fileConfig = new File(copy); + if (!fileConfig.exists()) { + refreshUserCopy(original, copy); + } + } + + /** + * Refresh configuration file in the user directory with Scilab defaults. + */ + public static void refreshUserCopy(String original, String copy) { + /* Create a local copy of the configuration file */ + try { + copyFile(new File(original), new File(copy)); + } catch (IOException e) { + System.err.println(ERROR_READ + copy); + } + } + + /** + * Copy a file + * @param in src file + * @param out dest file + * @throws FileNotFoundException + */ + protected static void copyFile(final File in, final File out) throws IOException { + FileInputStream fis = new FileInputStream(in); + FileOutputStream fos = new FileOutputStream(out); + + byte[] buf = new byte[BUFSIZE]; + int i = 0; + try { + while ((i = fis.read(buf)) != -1) { + fos.write(buf, 0, i); + } + fis.close(); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Read the file to modify + */ + protected static Document readDocument(final String fileName) { + File xml = new File(fileName); + DocumentBuilder docBuilder = null; + + try { + DocumentBuilderFactory factory = ScilabDocumentBuilderFactory.newInstance(); + docBuilder = factory.newDocumentBuilder(); + return docBuilder.parse(xml); + } catch (ParserConfigurationException pce) { + System.err.println(ERROR_READ + fileName); + } catch (SAXException se) { + System.err.println(ERROR_READ + fileName); + } catch (IOException ioe) { + System.err.println(ERROR_READ + fileName); + } + return null; + } + + /** + * Save the modifications + */ + protected static void writeDocument(String filename, Node written) { + Transformer transformer = null; + try { + transformer = ScilabTransformerFactory.newInstance().newTransformer(); + } catch (TransformerConfigurationException e1) { + System.err.println(ERROR_WRITE + filename); + } catch (TransformerFactoryConfigurationError e1) { + System.err.println(ERROR_WRITE + filename); + } + 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); + } + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/XComponent.java b/modules/preferences/src/java/org/scilab/modules/preferences/XComponent.java new file mode 100755 index 000000000..d3919d6de --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/XComponent.java @@ -0,0 +1,38 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences; + +import org.w3c.dom.Node; + +/** XComponent implements scilab components compliant with XManagement. + * + * @author Pierre GRADIT + */ +public interface XComponent { + + // CAUTION : Layout information have to be set in constructor! + + /** Define the set of actuators. + * + * @return array of actuator names. + */ + String [] actuators(); + + /** Refresh the component by the use of actuators. + * + * @param peer the corresponding view DOM node + */ + void refresh(Node peer); +} + + diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/XComponentAttributes.java b/modules/preferences/src/java/org/scilab/modules/preferences/XComponentAttributes.java new file mode 100755 index 000000000..afc11b547 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/XComponentAttributes.java @@ -0,0 +1,30 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - DIGITEO - Vincent COUVERT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences; + +/** + * XComponent attributes list + */ +public final class XComponentAttributes { + + public static final String BACKGROUND = "background"; + public static final String FOREGROUND = "foreground"; + public static final String TOOLTIP = "tooltip"; + + /** + * Constructor + */ + private XComponentAttributes() { + + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/XConfigManager.java b/modules/preferences/src/java/org/scilab/modules/preferences/XConfigManager.java new file mode 100755 index 000000000..3802a512a --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/XConfigManager.java @@ -0,0 +1,412 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - INRIA - Vincent COUVERT + * Copyright (C) 2011 - Pierre GRADIT + * Copyright (C) 2012-2014 - 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.1-en.txt + * + */ + +package org.scilab.modules.preferences; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Toolkit; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.ImageIcon; +import javax.swing.JDialog; + +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.scilab.modules.commons.ScilabCommons; +import org.scilab.modules.commons.ScilabCommonsUtils; +import org.scilab.modules.commons.ScilabConstants; +import org.scilab.modules.commons.gui.FindIconHelper; +import org.scilab.modules.commons.xml.XConfiguration; +import org.scilab.modules.localization.Messages; +import org.scilab.modules.gui.messagebox.ScilabModalDialog; +import org.scilab.modules.gui.messagebox.ScilabModalDialog.AnswerOption; +import org.scilab.modules.gui.messagebox.ScilabModalDialog.ButtonType; +import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType; +import org.scilab.modules.gui.utils.Position; +import org.scilab.modules.gui.utils.Size; +import org.scilab.modules.gui.utils.ScilabSwingUtilities; +import org.scilab.modules.gui.utils.WindowsConfigurationManager; +import org.scilab.modules.preferences.ScilabPreferences.ToolboxInfos; + +/** + * Extended management of the Console configuration file. + * + * @author Pierre GRADIT + * @author Vincent COUVERT + */ +public final class XConfigManager extends XCommonManager { + + private static final String RESET_DEFAULT_LAYOUT_QUESTION = Messages.gettext("Are you sure you want to restore the default layout at next startup?"); + private static final String RESET_LAYOUT_TITLE = Messages.gettext("Reset layout"); + + /** Exclusive activity flag between all XCommonManager descendants.*/ + public static boolean active = false; + + /** Scilab configuration file.*/ + private static final String SCILAB_CONFIG_FILE = System.getenv("SCI") + "/modules/preferences/etc/XConfiguration.xml"; + + /** Scilab configuration stylesheet.*/ + private static final String SCILAB_CONFIG_XSL = System.getenv("SCI") + "/modules/preferences/src/xslt/XConfiguration.xsl"; + + /** User configuration file.*/ + private static String USER_CONFIG_FILE; + private static boolean mustSave = true; + + static { + //ScilabPreferences.addToolboxInfos("MyToolbox", System.getenv("SCI") + "/contrib/toolbox_skeleton/", System.getenv("SCI") + "/contrib/toolbox_skeleton/etc/toolbox_skeleton_preferences.xml"); + + if (ScilabConstants.SCIHOME != null && ScilabConstants.SCIHOME.canRead() && ScilabConstants.SCIHOME.canWrite()) { + USER_CONFIG_FILE = ScilabConstants.SCIHOME.toString() + "/XConfiguration.xml"; + } else { + USER_CONFIG_FILE = SCILAB_CONFIG_FILE; + mustSave = false; + } + } + + /** + * Constructor blocked, singleton pattern. + */ + private XConfigManager() { + throw new UnsupportedOperationException(); + } + + /** Display dialog and wait for events. + * + */ + public static void displayAndWait(String initialPath) { + XConfigManager.active = true; + XWizardManager.active = false; + + reloadTransformer(SCILAB_CONFIG_XSL); + Frame topWindow = XCommonManager.getTopLevel(); + + // Set up Swing Side + dialog = new JDialog(topWindow, Messages.gettext("Scilab Preferences"), true); + dialog.setIconImage(new ImageIcon(FindIconHelper.findIcon("preferences-system", "256x256")).getImage()); + topSwing = dialog.getContentPane(); + topSwing.setLayout(new BorderLayout()); + // AWT implies to set layout at construction time. + + // 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())); + } + } + }); + + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + cancel(); + } + }); + ScilabSwingUtilities.closeOnEscape(dialog); + + // Set up correspondence + correspondance = new HashMap<Component, XSentinel>(); + + // Let the show begin! + if (refreshDisplay()) { + // Center the dialog on the parent window + if (topWindow != null) { + int x = topWindow.getX() + (topWindow.getWidth() - dialog.getWidth()) / 2; + int y = topWindow.getY() + (topWindow.getHeight() - dialog.getHeight()) / 2; + dialog.setLocation(x, y); + } + + dialog.setVisible(true); + } + } + + /** + * Opens a dialog to setup preferences. + */ + public static void openPreferences(String initialPath) { + XConfigManager.displayAndWait(initialPath); + } + + /** + * Opens a dialog to setup preferences. + */ + public static void openPreferences() { + XConfigManager.displayAndWait(null); + } + + /** Secondary dialog for help.*/ + private static JDialog help = null; + + /** Read files to modify (and possibly create it). + */ + private static void readUserDocuments() { + /* + * The default document just contains an empty tag <toolboxes/> + * We add a body and the different toolbox entries to have something like + * <toolboxes> + * <body/> + * <mytoolbox1><body>...</body></mytoolbox1> + * <mytoolbox2><body>...</body></mytoolbox2> + * </toolboxes> + */ + + document = XConfiguration.getXConfigurationDocument(); + + // We remove all the previous tags (should be empty but an error could have occurred...) + NodeList toolboxes = document.getElementsByTagName("toolboxes"); + for (int i = 0; i < toolboxes.getLength(); i++) { + try { + document.getDocumentElement().removeChild(toolboxes.item(i)); + } catch (Exception e) { + // Maybe root is not the good parent... + } + } + + Element tbxs = document.createElement("toolboxes"); + document.getDocumentElement().appendChild(tbxs); + + // Body (rendered as XConfiguration.xsl example) + Element body = document.createElement("body"); + tbxs.appendChild(body); + + List<ToolboxInfos> infos = ScilabPreferences.getToolboxesInfos(); + for (ToolboxInfos info : infos) { + String filename = new File(info.getPrefFile()).getName(); + String tbxTag = info.getName().replace(' ', '_'); + String tbxFile = ScilabConstants.SCIHOME.toString() + "/" + filename; + + // the copy is made only if needed + createUserCopy(info.getPrefFile(), tbxFile); + + // Building document fragment + Element token = document.createElement(tbxTag); + token.setAttribute("title", info.getName()); + DocumentFragment fragment = document.createDocumentFragment(); + Document tbxDocument = readDocument(tbxFile); + Node transferred = tbxDocument.getDocumentElement(); + + transferred = document.importNode(transferred, true); + fragment.appendChild(transferred); + token.insertBefore(fragment, null); + tbxs.appendChild(token); + } + } + + private static void WriteUserDocuments() { + // Toolboxes files + NodeList toolboxes = document.getElementsByTagName("toolboxes"); + Element tbxs = null; + Element emptyTbxs; + if (toolboxes != null && toolboxes.getLength() != 0) { + tbxs = (Element) toolboxes.item(0); + List<ToolboxInfos> infos = ScilabPreferences.getToolboxesInfos(); + for (ToolboxInfos info : infos) { + String tbxTag = info.getName().replace(' ', '_'); + NodeList list = tbxs.getElementsByTagName(tbxTag); + if (list != null && list.getLength() != 0) { + Element mytbx = (Element) list.item(0); + if (mytbx.hasChildNodes()) { + String filename = new File(info.getPrefFile()).getName(); + String tbxFile = ScilabConstants.SCIHOME.toString() + "/" + filename; + XConfiguration.writeDocument(tbxFile, mytbx.getFirstChild()); + } + } + } + } + + if (tbxs != null) { + document.getDocumentElement().removeChild(tbxs); + } + + XConfiguration.writeDocument(USER_CONFIG_FILE, document); + + if (tbxs != null) { + document.getDocumentElement().appendChild(tbxs); + } + } + + private static void cancel() { + dialog.dispose(); + XCommonManager.invalidateXSL(); + XConfiguration.invalidate(); + NodeList toolboxes = document.getElementsByTagName("toolboxes"); + if (toolboxes != null && toolboxes.getLength() != 0) { + Element tbxs = (Element) toolboxes.item(0); + document.getDocumentElement().removeChild(tbxs); + } + correspondance = null; + updated = false; + } + + /** Interpret action. + * + * @param action : to be interpreted. + * @param source : component source of the action (only class is needed). + * @return whether event was treated or not. + */ + public static boolean xEvent(final Node[] actions, final Component source) { + if (generixEvent(actions, source)) { + return true; + } + + if (actions.length == 0) { + return false; + } + + Node action = actions[0]; + String callback = getAttribute(action, "callback"); + /** help deprecated + if (callback.equals("Help")) { + // TODO it can be a contextual help. + //System.err.println("Help not implemented yet!"); + if (differential) { + System.out.println(": Help."); + } + return true; + } + **/ + if (callback.equals("Save Backup")) { + String path = getAttribute(action, "path"); + writeDocument(ScilabCommonsUtils.getCorrectedPath(path), document); + + return true; + } + + if (callback.equals("Reset layout")) { + if (ScilabModalDialog.show(dialog, new String[] {RESET_DEFAULT_LAYOUT_QUESTION}, RESET_LAYOUT_TITLE, IconType.QUESTION_ICON, ButtonType.YES_NO) == AnswerOption.NO_OPTION) { + return false; + } + + WindowsConfigurationManager.resetLayout(); + + return true; + } + + if (callback.equals("Restore Backup")) { + String path = getAttribute(action, "path"); + try { + copyFile(new File(ScilabCommonsUtils.getCorrectedPath(path)), new File(USER_CONFIG_FILE)); + } catch (IOException e) { + System.err.println(e); + } + + XConfiguration.invalidate(); + XConfiguration.addModifiedPath("ALL"); + reloadTransformer(SCILAB_CONFIG_XSL); + document = XConfiguration.createDocument(); + + List<ToolboxInfos> infos = ScilabPreferences.getToolboxesInfos(); + for (ToolboxInfos info : infos) { + String filename = new File(info.getPrefFile()).getName(); + String tbxFile = ScilabConstants.SCIHOME.toString() + "/" + filename; + refreshUserCopy(info.getPrefFile(), tbxFile); + } + readUserDocuments(); + updated = false; + refreshDisplay(); + + return true; + } + + if (callback.equals("Ok")) { + WriteUserDocuments(); + dialog.dispose(); + XCommonManager.invalidateXSL(); + updated = false; + XConfiguration.fireXConfigurationEvent(); + XConfiguration.invalidate(); + return true; + } + if (callback.equals("Apply")) { + updated = false; + WriteUserDocuments(); + XConfiguration.fireXConfigurationEvent(); + return true; + } + if (callback.equals("Default")) { + if (ScilabModalDialog.show(dialog, new String[] {Messages.gettext("Are you sure you want to reset all settings to the default values?")}, Messages.gettext("Reset"), IconType.QUESTION_ICON, ButtonType.YES_NO) == AnswerOption.NO_OPTION) { + return false; + } + + Cursor oldCursor = dialog.getContentPane().getCursor(); + dialog.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + XConfiguration.invalidate(); + XConfiguration.addModifiedPath("ALL"); + reloadTransformer(SCILAB_CONFIG_XSL); + document = XConfiguration.createDocument(); + writeDocument(USER_CONFIG_FILE, document); + List<ToolboxInfos> infos = ScilabPreferences.getToolboxesInfos(); + for (ToolboxInfos info : infos) { + String filename = new File(info.getPrefFile()).getName(); + String tbxFile = ScilabConstants.SCIHOME.toString() + "/" + filename; + refreshUserCopy(info.getPrefFile(), tbxFile); + } + readUserDocuments(); + updated = false; + refreshDisplay(); + + dialog.getContentPane().setCursor(oldCursor); + + return true; + } + if (callback.equals("Cancel")) { + cancel(); + return true; + } + return false; + } + + /** + * Save the modifications + */ + protected static void writeDocument(String filename, Node written) { + if (!SCILAB_CONFIG_FILE.equals(filename)) { + XCommonManager.writeDocument(filename, written); + } + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/XSentinel.java b/modules/preferences/src/java/org/scilab/modules/preferences/XSentinel.java new file mode 100755 index 000000000..78590f3a8 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/XSentinel.java @@ -0,0 +1,310 @@ +/* + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Set; +import java.util.TreeSet; + +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; + +import org.scilab.modules.preferences.Component.Table; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * XSentinel embeds correspondence between swing components and visible DOM + * nodes. Each instance has two functions : 1. Checks if a given node can be + * updated through actuators from the former one 2. Interprets incoming events + * and transmit corresponding action to XConfigManager. + * + * @author Pierre GRADIT + * + **/ +public class XSentinel implements MouseListener, ActionListener, TableModelListener, KeyListener, DocumentListener, PropertyChangeListener { + + private static final Set<String> LAYOUT = new TreeSet<String>(Arrays.asList(new String[] { "listener", "gridx", "gridy", "gridwidth", "gridheight", + "weightx", "weighty", "anchor", "ipadx", "ipday", "insets", "fill", "border-side", "fixed-height", "fixed-width" + })); + + /** + * Associated DOM Node. TODO Add accessors for this attribute. + */ + protected Node peer; + + /** + * Attributes which can be modified. TODO Add accessors for this attribute. + */ + protected String[] actuators; + + /** + * Reduced string for actuation test. TODO Add accessors for this attribute. + */ + public String reduced; + + /** + * Last time-stamp to avoid event duplication. + */ + private long timestamp = 0; + + private XComponent xComponent; + + /** + * Construction of a correspondence. + * + * @param component + * : Swing component + * @param node + * : DOM node + */ + public XSentinel(final Component component, final Node node) { + peer = node; + if (component instanceof XComponent) { + xComponent = (XComponent) component; + actuators = xComponent.actuators(); + } else { + actuators = new String[0]; + } + } + + /** + * Evaluate reachability through actuators as string equality. + * + * @param node + * : a given peer node to be reached. + * @param actuators + * : the set of actuators. + * @return the string verifying that string equality implies reachability + * through actuators. + */ + public static String signature(final Node node, final String[] actuators) { + StringBuilder signature = new StringBuilder(node.getNodeName()); + if (!node.hasAttributes()) { + return signature.toString(); + } + + // Filtering attributes against actuators (and grid layout constraint). + NamedNodeMap attributes = node.getAttributes(); + int size = attributes.getLength(); + Set<String> set = new TreeSet<String>(Arrays.asList(actuators)); + set.addAll(LAYOUT); + + for (int i = 0; i < size; i++) { + Node item = attributes.item(i); + String attrName = item.getNodeName(); + if (!set.contains(attrName)) { + /* + * As "actuators" can be performed without deleting node their + * value is removed from signature, grid layout manages + * "layout"... + */ + String value = item.getNodeValue().replaceAll("[ \t\n]+", " "); + signature.append(" "); + signature.append(attrName); + signature.append("='"); + signature.append(value); + signature.append("'"); + } + } + + return signature.toString(); + } + + public void setPeer(final Node next) { + peer = next; + } + + /** + * Check whether the next node can be reached through actuators. + * + * @param next + * : the node to be reached. + * @return can the node be reached ? + */ + public boolean checks(final Node next) { + String checker = signature(next, actuators); + if (reduced == null) { + reduced = signature(peer, actuators); + } + return reduced.equals(checker); + } + + /** + * Process event node through component. (must be updated if a new manager + * is created) + * + * @param component + * : the source of the action. + * @param node + * : the node embedding the action. + */ + boolean triggerEventNodes(final Component component, final Node[] nodes) { + if (XConfigManager.active) { + return XConfigManager.xEvent(nodes, component); + } + if (XWizardManager.active) { + return XWizardManager.xEvent(nodes, component); + } + return false; + } + + // + /** + * Returns the first event node of the given type. + * + * @param node + * : the node to browse. + * @param type + * : the seek type in peer children. + */ + Node[] getEventNodes(final Node node, final String type) { + ArrayList<Node> list = new ArrayList<Node>(); + NodeList nodelist = node.getChildNodes(); + for (int i = 0; i < nodelist.getLength(); i++) { + Node child = nodelist.item(i); + if (child.getNodeName().equals(type)) { + list.add(child); + } + } + + return list.toArray(new Node[list.size()]); + } + + /** Mouse listener callback. @param e : event */ + @Override + public void mouseClicked(final MouseEvent e) { + long when = e.getWhen(); + if (when != timestamp) { + Node[] action = getEventNodes(peer, "mouseClicked"); + triggerEventNodes((Component) e.getSource(), action); + timestamp = when; + } + } + + /** Mouse listener callback. @param e : event */ + @Override + public void mouseEntered(final MouseEvent e) { + } + + /** Mouse listener callback. @param e : event */ + @Override + public void mouseExited(final MouseEvent e) { + } + + /** Mouse listener callback. @param e : event */ + @Override + public void mousePressed(final MouseEvent e) { + } + + /** Mouse listener callback. @param e : event */ + @Override + public void mouseReleased(final MouseEvent e) { + } + + /** Action listener callback. @param e : event */ + @Override + public void actionPerformed(final ActionEvent e) { + long when = e.getWhen(); + if (when != timestamp) { + Node[] actions = getEventNodes(peer, "actionPerformed"); + if (actions.length == 0) { + actions = getEventNodes(peer, e.getActionCommand()); + } + if (actions.length != 0) { + triggerEventNodes((Component) e.getSource(), actions); + timestamp = when; + } + } else { + if (XConfigManager.differential) { + System.out.println(" | dummy actionPerformed discarded!"); + } + } + } + + /** Mouse listener callback. @param e : event */ + @Override + public void keyPressed(final KeyEvent e) { + } + + /** Mouse listener callback. @param e : event */ + @Override + public void keyReleased(final KeyEvent e) { + } + + /** Mouse listener callback. @param e : event */ + @Override + public void keyTyped(final KeyEvent e) { + long when = e.getWhen(); + if (when != timestamp) { + Node[] action = getEventNodes(peer, "keyTyped"); + triggerEventNodes((Component) e.getSource(), action); + timestamp = when; + } + } + + @Override + public void changedUpdate(DocumentEvent e) { + } + + @Override + public void insertUpdate(DocumentEvent e) { + Node[] action = getEventNodes(peer, "entryChanged"); + triggerEventNodes((Component) xComponent, action); + } + + @Override + public void removeUpdate(DocumentEvent e) { + Node[] action = getEventNodes(peer, "entryChanged"); + triggerEventNodes((Component) xComponent, action); + } + + /** Table listener callback. @param e : event */ + @Override + public void tableChanged(final TableModelEvent e) { + Node[] actions = getEventNodes(peer, "tableChanged"); + Table.processModelEvent(e, actions); + triggerEventNodes(null, actions); + // source is used for "choose" behavior not "set" ones. + } + + /** Global property change listener */ + @Override + public void propertyChange(final PropertyChangeEvent e) { + Node[] action = getEventNodes(peer, "propertyChange"); + final ArrayList<Node> called = new ArrayList<Node>(action.length); + + for (Node a : action) { + final String name = XCommonManager.getAttribute(a, "name", null); + + if (name == null || name.equals(e.getPropertyName())) { + called.add(a); + } + } + triggerEventNodes((Component) xComponent, called.toArray(new Node[called.size()])); + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/XUpdateVisitor.java b/modules/preferences/src/java/org/scilab/modules/preferences/XUpdateVisitor.java new file mode 100755 index 000000000..cc7aecef4 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/XUpdateVisitor.java @@ -0,0 +1,329 @@ +/* + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences; + +import java.awt.Component; +import java.awt.Container; +import java.util.Map; + +import javax.swing.AbstractButton; + +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.TextArea; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Updates swing component to reach correspondence with dom nodes. + */ +public class XUpdateVisitor { + + /** + * stores preceding correspondence to compute diff. + */ + private final Map<Component, XSentinel> matching; + + /** + * Construction of visitor. + * + * @param table + * : previous correspondence. + */ + public XUpdateVisitor(final Map<Component, XSentinel> table) { + matching = table; + } + + /** + * build a component from scratch with a given node. + * + * @param view + * : container of the built component. + * @param peer + * : peer of the container. + * @param item + * : peer of the built component. + * @param index + * : component index in container layout. + * @return a built component inserted in its container. + */ + public final Component build(final Container view, final Node peer, final Node item, final int index) { + Component component = buildPeerFor(item); + Object constraints = getLayoutConstraints(peer, item); + if (index >= 0) { + view.add(component, constraints, index); + } else { + view.add(component, constraints); + } + return component; + } + + /** + * Suppress a component. + * + * @param view + * : container of the suppressed component. + * @param component + * : suppressed component. + */ + public final void forget(final Container view, final Component component) { + view.remove(component); + matching.remove(component); + } + + /** + * Computes a recursive diff on both tree structure to achieve + * correspondence. + * + * @param view + * : the visited container. + * @param peer + * : the visited node. + */ + public final void visit(final Container view, final Node peer) { + int visibleIndex = 0; + int count; + NodeList nodes = peer.getChildNodes(); + int size = nodes.getLength(); + Component component; + XSentinel sentinel; + String indent; + + if (view instanceof Scroll) { + count = ((Scroll) view).getXComponentCount(); + } else { + count = view.getComponentCount(); + } + + for (int allIndex = 0; allIndex < size; allIndex++) { + Node item = nodes.item(allIndex); + if (isVisible(item)) { + if (visibleIndex < count) { + if (view instanceof Scroll) { + component = ((Scroll) view).getXComponent(visibleIndex); + } else { + component = view.getComponent(visibleIndex); + } + sentinel = matching.get(component); + if (sentinel == null || !sentinel.checks(item)) { + forget(view, component); + component = build(view, peer, item, visibleIndex); + } + } else { + component = build(view, peer, item, -1); + } + if (component instanceof XComponent) { + // Rebuild container children. + Container container = (Container) component; + visit(container, item); + } + visibleIndex++; + } + } + + // Clean children tail. + while (visibleIndex < view.getComponentCount()) { + component = view.getComponent(visibleIndex); + if (component instanceof XComponent) { + forget(view, component); + continue; + } + visibleIndex++; + } + + // Sentinel sets watch. + sentinel = matching.get(view); + if (sentinel == null) { + sentinel = new XSentinel(view, peer); + matching.put(view, sentinel); + if (view instanceof XComponent) { + addListeners(view, peer, sentinel); + } + } else { + sentinel.setPeer(peer); + } + // Attribute correspondence once children rebuilt. + if (view instanceof XComponent) { + XComponent xView = (XComponent) view; + xView.refresh(peer); + } + } + + /** + * Builds the layout constraint object. + * + * @param parent + * : parent node + * @param current + * : current node + * @return layout constraint (e.g. border side for border layout) + */ + final Object getLayoutConstraints(final Node parent, final Node current) { + if (XConfigManager.getAttribute(parent, "layout").equals("border")) { + return XConfigManager.getAttribute(current, "border-side"); + } + + if (parent.getNodeName().equals("Grid")) { + return current; + } + return null; + } + + /** + * Checks whether a node is visible or not. + * + * @param node + * : the checked node + * @return its visibility + */ + public final boolean isVisible(final Node node) { + // a. Event nodes are invisibles. + if (node.getNodeName().equals("mouseClicked")) { + return false; + } + if (node.getNodeName().equals("actionPerformed")) { + return false; + } + if (node.getNodeName().equals("entryChanged")) { + return false; + } + if (node.getNodeName().startsWith("propertyChange")) { + return false; + } + // b. Text nodes with only invisible characters are invisible. + if (node.getNodeName().equals("#text")) { + if (node.getNodeValue().replaceAll("^[ \t\n]+$", "").equals("")) { + return false; + } + } + // c. Chooser options are invisible. + if (node.getNodeName().equals("option")) { + return false; + } + // d. Table descriptors are invisible. + if (node.getNodeName().startsWith("table")) { + return false; + } + + // d. List element are invisible. + if (node.getNodeName().equals("listElement")) { + return false; + } + + // d. List element are invisible. + if (node.getNodeName().equals("html")) { + return false; + } + return true; + } + + /** + * Link XSentinal as listener for the given component. + * + * @param component + * : listened component + * @param node + * : peer node of the component + * @param sentinel + * : listener of component, node interpreter + */ + public final void addListeners(final Component component, final Node node, final XSentinel sentinel) { + String listener = XCommonManager.getAttribute(node, "listener"); + if (listener.equals("ActionListener")) { + if (component instanceof AbstractButton) { + AbstractButton button = (AbstractButton) component; + button.addActionListener(sentinel); + return; + } + if (component instanceof XChooser) { + XChooser chooser = (XChooser) component; + chooser.addActionListener(sentinel); + return; + } + } + + if (listener.equals("MouseListener")) { + // component.addKeyListener(sentinel); Provide focus with proper + // focus policy. + component.addMouseListener(sentinel); + return; + } + + if (listener.equals("KeyListener")) { + component.addKeyListener(sentinel); + return; + } + + if (listener.equals("EntryListener")) { + if (component instanceof Entry) { + ((Entry) component).getDocument().addDocumentListener(sentinel); + return; + } + + if (component instanceof FileSelector) { + ((FileSelector) component).addDocumentListener(sentinel); + return; + } + + if (component instanceof TextArea) { + ((TextArea) component).addDocumentListener(sentinel); + return; + } + } + + if (listener.equals("TableListener")) { + if (component instanceof Table) { + Table table = (Table) component; + table.addTableModelListener(sentinel); + return; + } + } + + if (listener.startsWith("PropertyChangeListener")) { + final int nameIndex = listener.indexOf('#'); + final boolean hasPropertyName = nameIndex > 0; + + final String propertyName; + if (hasPropertyName) { + propertyName = listener.substring(nameIndex + 1); + } else { + propertyName = null; + } + + if (component instanceof java.awt.Component) { + if (hasPropertyName) { + component.addPropertyChangeListener(propertyName, sentinel); + } else { + component.addPropertyChangeListener(sentinel); + } + + return; + } + } + } + + /** + * Build component from scratch with its node description. + * + * @param node + * : description of component + * @return the built component + */ + @SuppressWarnings("unchecked") + public final Component buildPeerFor(final Node node) { + return ComponentFactory.getComponent(node); + } +} diff --git a/modules/preferences/src/java/org/scilab/modules/preferences/XWizardManager.java b/modules/preferences/src/java/org/scilab/modules/preferences/XWizardManager.java new file mode 100755 index 000000000..a5524ec21 --- /dev/null +++ b/modules/preferences/src/java/org/scilab/modules/preferences/XWizardManager.java @@ -0,0 +1,270 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - INRIA - Vincent COUVERT + * Copyright (C) 2011 - Pierre GRADIT + * + * 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.1-en.txt + * + */ + +package org.scilab.modules.preferences; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.util.HashMap; + +import javax.swing.JDialog; + +import org.scilab.modules.gui.filechooser.Juigetfile; +import org.w3c.dom.Node; + +public final class XWizardManager extends XCommonManager { + /** Scilab wizard header file.*/ + private static final String SCILAB_WIZARD_FILE = + System.getenv("SCI") + "/modules/preferences/etc/XWizard.xml"; + + /** Scilab wizard prefix.*/ + private static final String SCILAB_WIZARD_PREFIX = + System.getenv("SCI") + "/modules/preferences/etc/XWizard-"; + + /** Scilab configuration stylesheet.*/ + private static final String SCILAB_WIZARD_XSL = + System.getenv("SCI") + "/modules/preferences/src/xslt/XWizard.xsl"; + + /** Current file name.*/ + private static String CURRENT_WIZARD_FILE = NAV; + + /** + * Constructor blocked, singleton pattern. + */ + private XWizardManager() { + throw new UnsupportedOperationException(); + } + + /** Exclusive activity flag between all XCommonManager descendants.*/ + public static boolean active = false; + + /** Display dialog and wait for events. + * + */ + public static void displayAndWait() { + XWizardManager.active = true; + XConfigManager.active = false; + printTimeStamp("XWizardManager launched"); + System.out.println(" | No active manager (" + XConfigManager.active + ", " + XWizardManager.active + ")."); + + reloadTransformer(SCILAB_WIZARD_XSL); + printTimeStamp("XSL loaded"); + + // Set up Swing Side + dialog = new JDialog(getTopLevel(), "Scilab wizard", true); + topSwing = dialog.getContentPane(); + //dialog = new SwingScilabTab("Scilab Preferences"); + //topSwing = new JPanel(); + dialog.setContentPane(topSwing); + topSwing.setLayout(new BorderLayout()); + // AWT implies to set layout at construction time. + + // Set up DOM Side + document = readDocument(SCILAB_WIZARD_FILE); + updated = false; + printTimeStamp("Model XML loaded"); + + // Set up correspondence + correspondance = new HashMap<Component, XSentinel>(); + + // Let the show begin! + if (refreshDisplay()) { + dialog.setVisible(true); + } + } + + /** + * Opens a dialog to setup user blocks. + */ + public static void openUserBlockWizard() { + //TODO temporary plug. + XWizardManager.displayAndWait(); + } + + /** Interpret action. + * + * @param action : to be interpreted. + * @param source : component source of the action (only class is needed). + * @return whether event was treated or not. + */ + public static boolean xEvent(final Node [] actions, final Component source) { + if (generixEvent(actions, source)) { + return true; + } + + if (actions.length == 0) { + //C System.out.println("No actions processed!"); + return false; + } + Node action = actions[0]; + String callback = getAttribute(action, "callback"); + if (callback.equals("load")) { + String name = getAttribute(action, "name"); + if (differential) { + System.out.println(": Load '" + SCILAB_WIZARD_PREFIX + name + ".xml'."); + } + dialog.setTitle("Scilab wizard - (" + name + " mode)"); + document = readDocument(SCILAB_WIZARD_PREFIX + name + ".xml" ); + printTimeStamp("XML loaded"); + refreshDisplay(); + updated = false; + return true; + } + if (callback.equals("New")) { + // TODO it can be a contextual help. + //System.err.println("Help not implemented yet!"); + if (differential) { + System.out.println(": New."); + } + reloadTransformer(SCILAB_WIZARD_XSL); + printTimeStamp("XSL loaded"); + document = readDocument(SCILAB_WIZARD_FILE); + printTimeStamp("XML loaded"); + updated = false; + refreshDisplay(); + return true; + } + + if (callback.equals("Open")) { + if (differential) { + System.out.println(": Open."); + } + String mask[] = {"*.xml"}; + String desc[] = {"Block description"}; + Juigetfile.uigetfile(mask, desc); + String selection[] = Juigetfile.getSelection(); + if (selection.length > 0) { + document = readDocument(selection[0]); + dialog.setTitle("Scilab wizard - <<" + selection[0] + ">>"); + printTimeStamp("XML loaded"); + updated = false; + refreshDisplay(); + } + return true; + } + + if (callback.equals("SaveAs")) { + if (differential) { + System.out.println(": Save as."); + } + String mask[] = {"*.xml"}; + String desc[] = {"Block description"}; + Juigetfile.uiputfile(mask, desc); + String selection[] = Juigetfile.getSelection(); + if (selection.length > 0) { + CURRENT_WIZARD_FILE = selection[0]; + } + if (CURRENT_WIZARD_FILE != NAV) { + writeDocument(CURRENT_WIZARD_FILE, document); + dialog.setTitle("Scilab wizard - [" + CURRENT_WIZARD_FILE + "]"); + } + return true; + } + + if (callback.equals("Save")) { + if (differential) { + System.out.println(": Save."); + } + if (CURRENT_WIZARD_FILE == NAV) { + String mask[] = {"*.xml"}; + String desc[] = {"Block description"}; + Juigetfile.uiputfile(mask, desc); + String selection[] = Juigetfile.getSelection(); + if (selection.length > 0) { + CURRENT_WIZARD_FILE = selection[0]; + } + } + if (CURRENT_WIZARD_FILE != NAV) { + writeDocument(CURRENT_WIZARD_FILE, document); + } + return true; + } + + /**** + if (callback.equals("Help")) { + // TODO it can be a contextual help. + //System.err.println("Help not implemented yet!"); + if (differential) { + System.out.println(": Help."); + } + return true; + } + if (callback.equals("Apply")) { + //System.err.println("User XML saved!"); + updated = false; + if (differential) { + System.out.println(": Apply."); + } + writeDocument(USER_CONFIG_FILE); + return true; + } + if (callback.equals("Default")) { + //System.out.println("Scilab XML reloaded!"); + if (differential) { + System.out.println(": Default."); + } + reloadTransformer(SCILAB_CONFIG_XSL); + refreshUserCopy(SCILAB_CONFIG_FILE, USER_CONFIG_FILE); + readUserDocument(); + printTimeStamp("XSL Reloaded"); + updated = false; + refreshDisplay(); + return true; + } + if (callback.equals("Cancel")) { + //System.err.println("User XML reloaded!"); + readUserDocument(); + // TODO advertise it! + //if (updated) { + // <<some advertising statement>> + // } + updated = false; + if (differential) { + System.out.println(": Cancel."); + } + refreshDisplay(); + return true; + }*****/ + if (callback.equals("Ok")) { + if (differential) { + System.out.println(": Ok."); + } + dialog.dispose(); + updated = false; + return true; + } + if (callback.equals("Quit")) { + if (differential) { + System.out.println(": Quit."); + } + dialog.dispose(); + updated = false; + return true; + } + + return false; + } + + /** TODO How to impact modification of wizard ? + * clearly an issue in this case as activity is lost so far! + */ + public static void subscribeUpdate() { + } + + /** TODO How to impact modification of preferences ? + * + */ + public static void notifyUpdate() { + } + +}
\ No newline at end of file diff --git a/modules/preferences/src/jni/.deps/.dirstamp b/modules/preferences/src/jni/.deps/.dirstamp new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/modules/preferences/src/jni/.deps/.dirstamp diff --git a/modules/preferences/src/jni/.deps/libscipreferences_la-ScilabPreferences.Plo b/modules/preferences/src/jni/.deps/libscipreferences_la-ScilabPreferences.Plo new file mode 100755 index 000000000..4142206f6 --- /dev/null +++ b/modules/preferences/src/jni/.deps/libscipreferences_la-ScilabPreferences.Plo @@ -0,0 +1,341 @@ +src/jni/libscipreferences_la-ScilabPreferences.lo: \ + src/jni/ScilabPreferences.cpp /usr/include/stdc-predef.h \ + src/jni/ScilabPreferences.hxx /usr/include/c++/5/iostream \ + /usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h \ + /usr/include/x86_64-linux-gnu/c++/5/bits/os_defines.h \ + /usr/include/features.h /usr/include/x86_64-linux-gnu/sys/cdefs.h \ + /usr/include/x86_64-linux-gnu/bits/wordsize.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \ + /usr/include/x86_64-linux-gnu/c++/5/bits/cpu_defines.h \ + /usr/include/c++/5/ostream /usr/include/c++/5/ios \ + /usr/include/c++/5/iosfwd /usr/include/c++/5/bits/stringfwd.h \ + /usr/include/c++/5/bits/memoryfwd.h /usr/include/c++/5/bits/postypes.h \ + /usr/include/c++/5/cwchar /usr/include/wchar.h /usr/include/stdio.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \ + /usr/include/x86_64-linux-gnu/bits/wchar.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h /usr/include/xlocale.h \ + /usr/include/x86_64-linux-gnu/bits/wchar2.h /usr/include/c++/5/exception \ + /usr/include/c++/5/bits/atomic_lockfree_defines.h \ + /usr/include/c++/5/bits/char_traits.h \ + /usr/include/c++/5/bits/stl_algobase.h \ + /usr/include/c++/5/bits/functexcept.h \ + /usr/include/c++/5/bits/exception_defines.h \ + /usr/include/c++/5/bits/cpp_type_traits.h \ + /usr/include/c++/5/ext/type_traits.h \ + /usr/include/c++/5/ext/numeric_traits.h \ + /usr/include/c++/5/bits/stl_pair.h /usr/include/c++/5/bits/move.h \ + /usr/include/c++/5/bits/concept_check.h \ + /usr/include/c++/5/bits/stl_iterator_base_types.h \ + /usr/include/c++/5/bits/stl_iterator_base_funcs.h \ + /usr/include/c++/5/debug/debug.h /usr/include/c++/5/bits/stl_iterator.h \ + /usr/include/c++/5/bits/ptr_traits.h \ + /usr/include/c++/5/bits/predefined_ops.h \ + /usr/include/c++/5/bits/localefwd.h \ + /usr/include/x86_64-linux-gnu/c++/5/bits/c++locale.h \ + /usr/include/c++/5/clocale /usr/include/locale.h \ + /usr/include/x86_64-linux-gnu/bits/locale.h /usr/include/c++/5/cctype \ + /usr/include/ctype.h /usr/include/x86_64-linux-gnu/bits/types.h \ + /usr/include/x86_64-linux-gnu/bits/typesizes.h /usr/include/endian.h \ + /usr/include/x86_64-linux-gnu/bits/endian.h \ + /usr/include/x86_64-linux-gnu/bits/byteswap.h \ + /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \ + /usr/include/c++/5/bits/ios_base.h /usr/include/c++/5/ext/atomicity.h \ + /usr/include/x86_64-linux-gnu/c++/5/bits/gthr.h \ + /usr/include/x86_64-linux-gnu/c++/5/bits/gthr-default.h \ + /usr/include/pthread.h /usr/include/sched.h /usr/include/time.h \ + /usr/include/x86_64-linux-gnu/bits/sched.h \ + /usr/include/x86_64-linux-gnu/bits/time.h \ + /usr/include/x86_64-linux-gnu/bits/timex.h \ + /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \ + /usr/include/x86_64-linux-gnu/bits/setjmp.h \ + /usr/include/x86_64-linux-gnu/c++/5/bits/atomic_word.h \ + /usr/include/c++/5/bits/locale_classes.h /usr/include/c++/5/string \ + /usr/include/c++/5/bits/allocator.h \ + /usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h \ + /usr/include/c++/5/ext/new_allocator.h /usr/include/c++/5/new \ + /usr/include/c++/5/bits/ostream_insert.h \ + /usr/include/c++/5/bits/cxxabi_forced.h \ + /usr/include/c++/5/bits/stl_function.h \ + /usr/include/c++/5/backward/binders.h \ + /usr/include/c++/5/bits/range_access.h \ + /usr/include/c++/5/bits/basic_string.h \ + /usr/include/c++/5/ext/alloc_traits.h \ + /usr/include/c++/5/bits/basic_string.tcc \ + /usr/include/c++/5/bits/locale_classes.tcc /usr/include/c++/5/stdexcept \ + /usr/include/c++/5/streambuf /usr/include/c++/5/bits/streambuf.tcc \ + /usr/include/c++/5/bits/basic_ios.h \ + /usr/include/c++/5/bits/locale_facets.h /usr/include/c++/5/cwctype \ + /usr/include/wctype.h \ + /usr/include/x86_64-linux-gnu/c++/5/bits/ctype_base.h \ + /usr/include/c++/5/bits/streambuf_iterator.h \ + /usr/include/x86_64-linux-gnu/c++/5/bits/ctype_inline.h \ + /usr/include/c++/5/bits/locale_facets.tcc \ + /usr/include/c++/5/bits/basic_ios.tcc \ + /usr/include/c++/5/bits/ostream.tcc /usr/include/c++/5/istream \ + /usr/include/c++/5/bits/istream.tcc /usr/include/string.h \ + /usr/include/x86_64-linux-gnu/bits/string3.h /usr/include/stdlib.h \ + /usr/include/x86_64-linux-gnu/bits/waitflags.h \ + /usr/include/x86_64-linux-gnu/bits/waitstatus.h \ + /usr/include/x86_64-linux-gnu/sys/types.h \ + /usr/include/x86_64-linux-gnu/sys/select.h \ + /usr/include/x86_64-linux-gnu/bits/select.h \ + /usr/include/x86_64-linux-gnu/bits/sigset.h \ + /usr/include/x86_64-linux-gnu/bits/select2.h \ + /usr/include/x86_64-linux-gnu/sys/sysmacros.h /usr/include/alloca.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \ + /usr/include/x86_64-linux-gnu/bits/stdlib.h \ + /usr/lib/jvm/java-8-openjdk-amd64/include/jni.h /usr/include/libio.h \ + /usr/include/_G_config.h /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \ + /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \ + /usr/include/x86_64-linux-gnu/bits/stdio.h \ + /usr/include/x86_64-linux-gnu/bits/stdio2.h \ + /usr/lib/jvm/java-8-openjdk-amd64/include/linux/jni_md.h \ + ../../modules/commons/src/jni/GiwsException.hxx + +/usr/include/stdc-predef.h: + +src/jni/ScilabPreferences.hxx: + +/usr/include/c++/5/iostream: + +/usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h: + +/usr/include/x86_64-linux-gnu/c++/5/bits/os_defines.h: + +/usr/include/features.h: + +/usr/include/x86_64-linux-gnu/sys/cdefs.h: + +/usr/include/x86_64-linux-gnu/bits/wordsize.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs-64.h: + +/usr/include/x86_64-linux-gnu/c++/5/bits/cpu_defines.h: + +/usr/include/c++/5/ostream: + +/usr/include/c++/5/ios: + +/usr/include/c++/5/iosfwd: + +/usr/include/c++/5/bits/stringfwd.h: + +/usr/include/c++/5/bits/memoryfwd.h: + +/usr/include/c++/5/bits/postypes.h: + +/usr/include/c++/5/cwchar: + +/usr/include/wchar.h: + +/usr/include/stdio.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h: + +/usr/include/x86_64-linux-gnu/bits/wchar.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h: + +/usr/include/xlocale.h: + +/usr/include/x86_64-linux-gnu/bits/wchar2.h: + +/usr/include/c++/5/exception: + +/usr/include/c++/5/bits/atomic_lockfree_defines.h: + +/usr/include/c++/5/bits/char_traits.h: + +/usr/include/c++/5/bits/stl_algobase.h: + +/usr/include/c++/5/bits/functexcept.h: + +/usr/include/c++/5/bits/exception_defines.h: + +/usr/include/c++/5/bits/cpp_type_traits.h: + +/usr/include/c++/5/ext/type_traits.h: + +/usr/include/c++/5/ext/numeric_traits.h: + +/usr/include/c++/5/bits/stl_pair.h: + +/usr/include/c++/5/bits/move.h: + +/usr/include/c++/5/bits/concept_check.h: + +/usr/include/c++/5/bits/stl_iterator_base_types.h: + +/usr/include/c++/5/bits/stl_iterator_base_funcs.h: + +/usr/include/c++/5/debug/debug.h: + +/usr/include/c++/5/bits/stl_iterator.h: + +/usr/include/c++/5/bits/ptr_traits.h: + +/usr/include/c++/5/bits/predefined_ops.h: + +/usr/include/c++/5/bits/localefwd.h: + +/usr/include/x86_64-linux-gnu/c++/5/bits/c++locale.h: + +/usr/include/c++/5/clocale: + +/usr/include/locale.h: + +/usr/include/x86_64-linux-gnu/bits/locale.h: + +/usr/include/c++/5/cctype: + +/usr/include/ctype.h: + +/usr/include/x86_64-linux-gnu/bits/types.h: + +/usr/include/x86_64-linux-gnu/bits/typesizes.h: + +/usr/include/endian.h: + +/usr/include/x86_64-linux-gnu/bits/endian.h: + +/usr/include/x86_64-linux-gnu/bits/byteswap.h: + +/usr/include/x86_64-linux-gnu/bits/byteswap-16.h: + +/usr/include/c++/5/bits/ios_base.h: + +/usr/include/c++/5/ext/atomicity.h: + +/usr/include/x86_64-linux-gnu/c++/5/bits/gthr.h: + +/usr/include/x86_64-linux-gnu/c++/5/bits/gthr-default.h: + +/usr/include/pthread.h: + +/usr/include/sched.h: + +/usr/include/time.h: + +/usr/include/x86_64-linux-gnu/bits/sched.h: + +/usr/include/x86_64-linux-gnu/bits/time.h: + +/usr/include/x86_64-linux-gnu/bits/timex.h: + +/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h: + +/usr/include/x86_64-linux-gnu/bits/setjmp.h: + +/usr/include/x86_64-linux-gnu/c++/5/bits/atomic_word.h: + +/usr/include/c++/5/bits/locale_classes.h: + +/usr/include/c++/5/string: + +/usr/include/c++/5/bits/allocator.h: + +/usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h: + +/usr/include/c++/5/ext/new_allocator.h: + +/usr/include/c++/5/new: + +/usr/include/c++/5/bits/ostream_insert.h: + +/usr/include/c++/5/bits/cxxabi_forced.h: + +/usr/include/c++/5/bits/stl_function.h: + +/usr/include/c++/5/backward/binders.h: + +/usr/include/c++/5/bits/range_access.h: + +/usr/include/c++/5/bits/basic_string.h: + +/usr/include/c++/5/ext/alloc_traits.h: + +/usr/include/c++/5/bits/basic_string.tcc: + +/usr/include/c++/5/bits/locale_classes.tcc: + +/usr/include/c++/5/stdexcept: + +/usr/include/c++/5/streambuf: + +/usr/include/c++/5/bits/streambuf.tcc: + +/usr/include/c++/5/bits/basic_ios.h: + +/usr/include/c++/5/bits/locale_facets.h: + +/usr/include/c++/5/cwctype: + +/usr/include/wctype.h: + +/usr/include/x86_64-linux-gnu/c++/5/bits/ctype_base.h: + +/usr/include/c++/5/bits/streambuf_iterator.h: + +/usr/include/x86_64-linux-gnu/c++/5/bits/ctype_inline.h: + +/usr/include/c++/5/bits/locale_facets.tcc: + +/usr/include/c++/5/bits/basic_ios.tcc: + +/usr/include/c++/5/bits/ostream.tcc: + +/usr/include/c++/5/istream: + +/usr/include/c++/5/bits/istream.tcc: + +/usr/include/string.h: + +/usr/include/x86_64-linux-gnu/bits/string3.h: + +/usr/include/stdlib.h: + +/usr/include/x86_64-linux-gnu/bits/waitflags.h: + +/usr/include/x86_64-linux-gnu/bits/waitstatus.h: + +/usr/include/x86_64-linux-gnu/sys/types.h: + +/usr/include/x86_64-linux-gnu/sys/select.h: + +/usr/include/x86_64-linux-gnu/bits/select.h: + +/usr/include/x86_64-linux-gnu/bits/sigset.h: + +/usr/include/x86_64-linux-gnu/bits/select2.h: + +/usr/include/x86_64-linux-gnu/sys/sysmacros.h: + +/usr/include/alloca.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: + +/usr/include/x86_64-linux-gnu/bits/stdlib.h: + +/usr/lib/jvm/java-8-openjdk-amd64/include/jni.h: + +/usr/include/libio.h: + +/usr/include/_G_config.h: + +/usr/include/x86_64-linux-gnu/bits/stdio_lim.h: + +/usr/include/x86_64-linux-gnu/bits/sys_errlist.h: + +/usr/include/x86_64-linux-gnu/bits/stdio.h: + +/usr/include/x86_64-linux-gnu/bits/stdio2.h: + +/usr/lib/jvm/java-8-openjdk-amd64/include/linux/jni_md.h: + +../../modules/commons/src/jni/GiwsException.hxx: diff --git a/modules/preferences/src/jni/.dirstamp b/modules/preferences/src/jni/.dirstamp new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/modules/preferences/src/jni/.dirstamp diff --git a/modules/preferences/src/jni/.libs/libscipreferences_la-ScilabPreferences.o b/modules/preferences/src/jni/.libs/libscipreferences_la-ScilabPreferences.o Binary files differnew file mode 100755 index 000000000..a8dfe165a --- /dev/null +++ b/modules/preferences/src/jni/.libs/libscipreferences_la-ScilabPreferences.o diff --git a/modules/preferences/src/jni/ScilabPreferences.cpp b/modules/preferences/src/jni/ScilabPreferences.cpp new file mode 100755 index 000000000..17e89955f --- /dev/null +++ b/modules/preferences/src/jni/ScilabPreferences.cpp @@ -0,0 +1,245 @@ +#include "ScilabPreferences.hxx" +/* Generated by GIWS (version 2.0.2) with command: +giws --disable-return-size-array --output-dir src/jni/ --throws-exception-on-error --description-file src/jni/ScilabPreferences.giws.xml +*/ +/* + +This is generated code. + +This software is a computer program whose purpose is to hide the complexity +of accessing Java objects/methods from C++ code. + +This software is governed by the CeCILL-B license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL-B +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL-B license and that you accept its terms. +*/ + +namespace org_scilab_modules_preferences { + + // Static declarations (if any) + +// Returns the current env + +JNIEnv * ScilabPreferences::getCurrentEnv() { +JNIEnv * curEnv = NULL; +jint res=this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL); +if (res != JNI_OK) { +throw GiwsException::JniException(getCurrentEnv()); +} +return curEnv; +} +// Destructor + +ScilabPreferences::~ScilabPreferences() { +JNIEnv * curEnv = NULL; +this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL); +curEnv->DeleteGlobalRef(this->instance); +curEnv->DeleteGlobalRef(this->instanceClass); +} +// Constructors +ScilabPreferences::ScilabPreferences(JavaVM * jvm_) { +jmethodID constructObject = NULL ; +jobject localInstance ; +jclass localClass ; + +const std::string construct="<init>"; +const std::string param="()V"; +jvm=jvm_; + +JNIEnv * curEnv = getCurrentEnv(); + +localClass = curEnv->FindClass( this->className().c_str() ) ; +if (localClass == NULL) { + throw GiwsException::JniClassNotFoundException(curEnv, this->className()); +} + +this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass)); + +/* localClass is not needed anymore */ +curEnv->DeleteLocalRef(localClass); + +if (this->instanceClass == NULL) { +throw GiwsException::JniObjectCreationException(curEnv, this->className()); +} + + +constructObject = curEnv->GetMethodID( this->instanceClass, construct.c_str() , param.c_str() ) ; +if(constructObject == NULL){ +throw GiwsException::JniObjectCreationException(curEnv, this->className()); +} + +localInstance = curEnv->NewObject( this->instanceClass, constructObject ) ; +if(localInstance == NULL){ +throw GiwsException::JniObjectCreationException(curEnv, this->className()); +} + +this->instance = curEnv->NewGlobalRef(localInstance) ; +if(this->instance == NULL){ +throw GiwsException::JniObjectCreationException(curEnv, this->className()); +} +/* localInstance not needed anymore */ +curEnv->DeleteLocalRef(localInstance); + + /* Methods ID set to NULL */ +voidaddToolboxInfosjstringjava_lang_Stringjstringjava_lang_Stringjstringjava_lang_StringID=NULL; +voidremoveToolboxInfosjstringjava_lang_StringID=NULL; +voidopenPreferencesID=NULL; + + +} + +ScilabPreferences::ScilabPreferences(JavaVM * jvm_, jobject JObj) { + jvm=jvm_; + + JNIEnv * curEnv = getCurrentEnv(); + +jclass localClass = curEnv->GetObjectClass(JObj); + this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass)); + curEnv->DeleteLocalRef(localClass); + + if (this->instanceClass == NULL) { +throw GiwsException::JniObjectCreationException(curEnv, this->className()); + } + + this->instance = curEnv->NewGlobalRef(JObj) ; + if(this->instance == NULL){ +throw GiwsException::JniObjectCreationException(curEnv, this->className()); + } + /* Methods ID set to NULL */ + voidaddToolboxInfosjstringjava_lang_Stringjstringjava_lang_Stringjstringjava_lang_StringID=NULL; +voidremoveToolboxInfosjstringjava_lang_StringID=NULL; +voidopenPreferencesID=NULL; + + +} + +// Generic methods + +void ScilabPreferences::synchronize() { +if (getCurrentEnv()->MonitorEnter(instance) != JNI_OK) { +throw GiwsException::JniMonitorException(getCurrentEnv(), "ScilabPreferences"); +} +} + +void ScilabPreferences::endSynchronize() { +if ( getCurrentEnv()->MonitorExit(instance) != JNI_OK) { +throw GiwsException::JniMonitorException(getCurrentEnv(), "ScilabPreferences"); +} +} +// Method(s) + +void ScilabPreferences::addToolboxInfos (JavaVM * jvm_, char const* name, char const* path, char const* prefFile){ + +JNIEnv * curEnv = NULL; +jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL); +jclass cls = initClass(curEnv); +if ( cls == NULL) { +throw GiwsException::JniCallMethodException(curEnv); +} + +static jmethodID voidaddToolboxInfosjstringjava_lang_Stringjstringjava_lang_Stringjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "addToolboxInfos", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V" ) ; +if (voidaddToolboxInfosjstringjava_lang_Stringjstringjava_lang_Stringjstringjava_lang_StringID == NULL) { +throw GiwsException::JniMethodNotFoundException(curEnv, "addToolboxInfos"); +} + +jstring name_ = curEnv->NewStringUTF( name ); +if (name != NULL && name_ == NULL) +{ +throw GiwsException::JniBadAllocException(curEnv); +} + + +jstring path_ = curEnv->NewStringUTF( path ); +if (path != NULL && path_ == NULL) +{ +throw GiwsException::JniBadAllocException(curEnv); +} + + +jstring prefFile_ = curEnv->NewStringUTF( prefFile ); +if (prefFile != NULL && prefFile_ == NULL) +{ +throw GiwsException::JniBadAllocException(curEnv); +} + + + curEnv->CallStaticVoidMethod(cls, voidaddToolboxInfosjstringjava_lang_Stringjstringjava_lang_Stringjstringjava_lang_StringID ,name_, path_, prefFile_); + curEnv->DeleteLocalRef(name_); +curEnv->DeleteLocalRef(path_); +curEnv->DeleteLocalRef(prefFile_); +if (curEnv->ExceptionCheck()) { +throw GiwsException::JniCallMethodException(curEnv); +} +} + +void ScilabPreferences::removeToolboxInfos (JavaVM * jvm_, char const* path){ + +JNIEnv * curEnv = NULL; +jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL); +jclass cls = initClass(curEnv); +if ( cls == NULL) { +throw GiwsException::JniCallMethodException(curEnv); +} + +static jmethodID voidremoveToolboxInfosjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "removeToolboxInfos", "(Ljava/lang/String;)V" ) ; +if (voidremoveToolboxInfosjstringjava_lang_StringID == NULL) { +throw GiwsException::JniMethodNotFoundException(curEnv, "removeToolboxInfos"); +} + +jstring path_ = curEnv->NewStringUTF( path ); +if (path != NULL && path_ == NULL) +{ +throw GiwsException::JniBadAllocException(curEnv); +} + + + curEnv->CallStaticVoidMethod(cls, voidremoveToolboxInfosjstringjava_lang_StringID ,path_); + curEnv->DeleteLocalRef(path_); +if (curEnv->ExceptionCheck()) { +throw GiwsException::JniCallMethodException(curEnv); +} +} + +void ScilabPreferences::openPreferences (JavaVM * jvm_){ + +JNIEnv * curEnv = NULL; +jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL); +jclass cls = initClass(curEnv); +if ( cls == NULL) { +throw GiwsException::JniCallMethodException(curEnv); +} + +static jmethodID voidopenPreferencesID = curEnv->GetStaticMethodID(cls, "openPreferences", "()V" ) ; +if (voidopenPreferencesID == NULL) { +throw GiwsException::JniMethodNotFoundException(curEnv, "openPreferences"); +} + + curEnv->CallStaticVoidMethod(cls, voidopenPreferencesID ); + if (curEnv->ExceptionCheck()) { +throw GiwsException::JniCallMethodException(curEnv); +} +} + +} diff --git a/modules/preferences/src/jni/ScilabPreferences.giws.xml b/modules/preferences/src/jni/ScilabPreferences.giws.xml new file mode 100755 index 000000000..6ce4841e9 --- /dev/null +++ b/modules/preferences/src/jni/ScilabPreferences.giws.xml @@ -0,0 +1,13 @@ + <package name="org.scilab.modules.preferences"> + <object name="ScilabPreferences"> + <method name="addToolboxInfos" returnType="void" modifier="static"> + <parameter name="name" type="String"/> + <parameter name="path" type="String"/> + <parameter name="prefFile" type="String"/> + </method> + <method name="removeToolboxInfos" returnType="void" modifier="static"> + <parameter name="path" type="String"/> + </method> + <method name="openPreferences" returnType="void" modifier="static" /> + </object> +</package> diff --git a/modules/preferences/src/jni/ScilabPreferences.hxx b/modules/preferences/src/jni/ScilabPreferences.hxx new file mode 100755 index 000000000..d650c10b5 --- /dev/null +++ b/modules/preferences/src/jni/ScilabPreferences.hxx @@ -0,0 +1,184 @@ +/* Generated by GIWS (version 2.0.2) with command: +giws --disable-return-size-array --output-dir src/jni/ --throws-exception-on-error --description-file src/jni/ScilabPreferences.giws.xml +*/ +/* + +This is generated code. + +This software is a computer program whose purpose is to hide the complexity +of accessing Java objects/methods from C++ code. + +This software is governed by the CeCILL-B license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL-B +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL-B license and that you accept its terms. +*/ + + +#ifndef __ORG_SCILAB_MODULES_PREFERENCES_SCILABPREFERENCES__ +#define __ORG_SCILAB_MODULES_PREFERENCES_SCILABPREFERENCES__ +#include <iostream> +#include <string> +#include <string.h> +#include <stdlib.h> +#include <jni.h> + +#include "GiwsException.hxx" + + #if defined(_MSC_VER) /* Defined anyway with Visual */ + #include <Windows.h> + #else + typedef signed char byte; + #endif + + +#ifndef GIWSEXPORT +# if defined(_MSC_VER) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(STATIC_LINKED) +# define GIWSEXPORT +# else +# define GIWSEXPORT __declspec(dllexport) +# endif +# else +# if __GNUC__ >= 4 +# define GIWSEXPORT __attribute__ ((visibility ("default"))) +# else +# define GIWSEXPORT +# endif +# endif +#endif + +namespace org_scilab_modules_preferences { +class GIWSEXPORT ScilabPreferences { + +private: +JavaVM * jvm; + +protected: +jmethodID voidaddToolboxInfosjstringjava_lang_Stringjstringjava_lang_Stringjstringjava_lang_StringID; // cache method id +jmethodID voidremoveToolboxInfosjstringjava_lang_StringID; // cache method id +jmethodID voidopenPreferencesID; // cache method id + + + +jobject instance; +jclass instanceClass; // cache class + + +// Caching (if any) + + +/** +* Get the environment matching to the current thread. +*/ +virtual JNIEnv * getCurrentEnv(); + +public: +// Constructor +/** +* Create a wrapping of the object from a JNIEnv. +* It will call the default constructor +* @param JEnv_ the Java Env +*/ +ScilabPreferences(JavaVM * jvm_); + +/** +* Create a wrapping of an already existing object from a JNIEnv. +* The object must have already been instantiated +* @param JEnv_ the Java Env +* @param JObj the object +*/ +ScilabPreferences(JavaVM * jvm_, jobject JObj); + + +/** +* This is a fake constructor to avoid the constructor +* chaining when dealing with extended giws classes +*/ +#ifdef FAKEGIWSDATATYPE +ScilabPreferences(fakeGiwsDataType::fakeGiwsDataType /* unused */) {} +#endif + +// Destructor +~ScilabPreferences(); + +// Generic method +// Synchronization methods +/** +* Enter monitor associated with the object. +* Equivalent of creating a "synchronized(obj)" scope in Java. +*/ +void synchronize(); + +/** +* Exit monitor associated with the object. +* Equivalent of ending a "synchronized(obj)" scope. +*/ +void endSynchronize(); + +// Methods +static void addToolboxInfos(JavaVM * jvm_, char const* name, char const* path, char const* prefFile); + +static void removeToolboxInfos(JavaVM * jvm_, char const* path); + +static void openPreferences(JavaVM * jvm_); + + + /** + * Get class name to use for static methods + * @return class name to use for static methods + */ + + static const std::string className() + { + return "org/scilab/modules/preferences/ScilabPreferences"; + } + + + /** + * Get class to use for static methods + * @return class to use for static methods + */ + + static jclass initClass(JNIEnv * curEnv) + { + static jclass cls = 0; + + if (cls == 0) + { + jclass _cls = curEnv->FindClass(className().c_str()); + if (_cls) + { + cls = static_cast<jclass>(curEnv->NewGlobalRef(_cls)); + } + } + + return cls; + } + +}; + + +} +#endif diff --git a/modules/preferences/src/jni/libscipreferences_la-ScilabPreferences.lo b/modules/preferences/src/jni/libscipreferences_la-ScilabPreferences.lo new file mode 100755 index 000000000..8ebd7ed87 --- /dev/null +++ b/modules/preferences/src/jni/libscipreferences_la-ScilabPreferences.lo @@ -0,0 +1,12 @@ +# src/jni/libscipreferences_la-ScilabPreferences.lo - a libtool object file +# Generated by libtool (GNU libtool) 2.4.2 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/libscipreferences_la-ScilabPreferences.o' + +# Name of the non-PIC object +non_pic_object=none + diff --git a/modules/preferences/src/nopreferences/.deps/.dirstamp b/modules/preferences/src/nopreferences/.deps/.dirstamp new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/modules/preferences/src/nopreferences/.deps/.dirstamp diff --git a/modules/preferences/src/nopreferences/.deps/libscipreferences_cli_la-nopreferences.Plo b/modules/preferences/src/nopreferences/.deps/libscipreferences_cli_la-nopreferences.Plo new file mode 100755 index 000000000..476a044c4 --- /dev/null +++ b/modules/preferences/src/nopreferences/.deps/libscipreferences_cli_la-nopreferences.Plo @@ -0,0 +1,49 @@ +src/nopreferences/libscipreferences_cli_la-nopreferences.lo: \ + src/nopreferences/nopreferences.c /usr/include/stdc-predef.h \ + src/nopreferences/nopreferences.h \ + ../../modules/output_stream/includes/Scierror.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \ + ../../modules/output_stream/includes/do_error_number.h \ + ../../modules/core/includes/machine.h \ + ../../modules/localization/includes/localization.h \ + /usr/include/libintl.h /usr/include/features.h \ + /usr/include/x86_64-linux-gnu/sys/cdefs.h \ + /usr/include/x86_64-linux-gnu/bits/wordsize.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs.h \ + /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \ + /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h /usr/include/locale.h \ + /usr/include/x86_64-linux-gnu/bits/locale.h /usr/include/xlocale.h + +/usr/include/stdc-predef.h: + +src/nopreferences/nopreferences.h: + +../../modules/output_stream/includes/Scierror.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h: + +../../modules/output_stream/includes/do_error_number.h: + +../../modules/core/includes/machine.h: + +../../modules/localization/includes/localization.h: + +/usr/include/libintl.h: + +/usr/include/features.h: + +/usr/include/x86_64-linux-gnu/sys/cdefs.h: + +/usr/include/x86_64-linux-gnu/bits/wordsize.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs.h: + +/usr/include/x86_64-linux-gnu/gnu/stubs-64.h: + +/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h: + +/usr/include/locale.h: + +/usr/include/x86_64-linux-gnu/bits/locale.h: + +/usr/include/xlocale.h: diff --git a/modules/preferences/src/nopreferences/.dirstamp b/modules/preferences/src/nopreferences/.dirstamp new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/modules/preferences/src/nopreferences/.dirstamp diff --git a/modules/preferences/src/nopreferences/.libs/libscipreferences_cli_la-nopreferences.o b/modules/preferences/src/nopreferences/.libs/libscipreferences_cli_la-nopreferences.o Binary files differnew file mode 100755 index 000000000..ff26aa200 --- /dev/null +++ b/modules/preferences/src/nopreferences/.libs/libscipreferences_cli_la-nopreferences.o diff --git a/modules/preferences/src/nopreferences/libscipreferences_cli_la-nopreferences.lo b/modules/preferences/src/nopreferences/libscipreferences_cli_la-nopreferences.lo new file mode 100755 index 000000000..760ea4af3 --- /dev/null +++ b/modules/preferences/src/nopreferences/libscipreferences_cli_la-nopreferences.lo @@ -0,0 +1,12 @@ +# src/nopreferences/libscipreferences_cli_la-nopreferences.lo - a libtool object file +# Generated by libtool (GNU libtool) 2.4.2 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/libscipreferences_cli_la-nopreferences.o' + +# Name of the non-PIC object +non_pic_object=none + diff --git a/modules/preferences/src/nopreferences/nopreferences.c b/modules/preferences/src/nopreferences/nopreferences.c new file mode 100755 index 000000000..8b21c2c45 --- /dev/null +++ b/modules/preferences/src/nopreferences/nopreferences.c @@ -0,0 +1,22 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - DIGITEO - 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.1-en.txt + * + */ +/*--------------------------------------------------------------------------*/ +#include "nopreferences.h" +#include "Scierror.h" +#include "localization.h" +/*--------------------------------------------------------------------------*/ +int gw_preferences(void) +{ + Scierror(999, _("Scilab '%s' module not installed.\n"), "preferences"); + return 0; +} +/*--------------------------------------------------------------------------*/ diff --git a/modules/preferences/src/nopreferences/nopreferences.h b/modules/preferences/src/nopreferences/nopreferences.h new file mode 100755 index 000000000..25d386f65 --- /dev/null +++ b/modules/preferences/src/nopreferences/nopreferences.h @@ -0,0 +1,14 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011 - DIGITEO - 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.1-en.txt + * + */ +/*--------------------------------------------------------------------------*/ +int gw_preferences(void); +/*--------------------------------------------------------------------------*/ diff --git a/modules/preferences/src/xslt/XCommon-toolbars.xsl b/modules/preferences/src/xslt/XCommon-toolbars.xsl new file mode 100755 index 000000000..c1bb0468d --- /dev/null +++ b/modules/preferences/src/xslt/XCommon-toolbars.xsl @@ -0,0 +1,47 @@ +<?xml version='1.0' encoding='utf-8'?> +<xsl:stylesheet version ="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +> + <xsl:variable name="core-toolbars"> + <toolbar title="scilab"> + <item title="Cut" icon="edit-cut.png" callScilabBridge='cutConsoleSelection'/> + <item title="Copy" icon="edit-copy.png" callScilabBridge='copyConsoleSelection'/> + <item title="Paste" icon="edit-paste.png" callScilabBridge='pasteClipboardIntoConsole'/> + <item title="Choose Font..." icon="format-text-bold.png" callScilabBridge='changeConsoleFont'/> + <item title="Print..." icon="printer.png" callScilabBridge='printConsoleContents'/> + <item title="Launch SciNotes" icon="accessories-text-editor.png" script='editor();' /> + <item title="Help Browser" icon="help-browser.png" script='help();' /> + <item title="Scilab Demonstrations" icon="applications-system.png" script='demo_gui();' /> + <item title="Open a file" icon="document-open.png" script=' + %fileToOpen = uigetfile("*.sc*", pwd(), gettext("Select a file to open with SciNotes")); + if ~(%fileToOpen == "") then + editor(%fileToOpen); + end + clear("%fileToOpen");'/> + <item title="Change folder" icon="folder.png" script=' + %newDir = uigetdir(pwd(), gettext("Select a directory")); + if ~(%newDir == "") then + cd(%newDir); + end + clear("%newDir");'/> + <item title="Module manager - ATOMS" icon="package-x-generic.png" script=' + if with_module("atoms") then + atomsGui(); + else + disp(gettext("Please install atoms module.")); + end'/> + <item title="Xcos" icon="utilities-system-monitor.png" script=' + if with_module("xcos") then + xcos(); + else + disp(gettext("Please install xcos module.")); + end'/> + </toolbar> + <toolbar title="scinotes"> + <item title="Cut" icon="edit-cut.png" callScilabBridge='cutConsoleSelection'/> + <item title="Copy" icon="edit-copy.png" callScilabBridge='copyConsoleSelection'/> + <item title="Paste" icon="edit-paste.png" callScilabBridge='pasteClipboardIntoConsole'/> + </toolbar> + </xsl:variable> + <xsl:variable name="toolbars" select="nodeset($core-toolbars)"/> +</xsl:stylesheet> diff --git a/modules/preferences/src/xslt/XCommon.xsl b/modules/preferences/src/xslt/XCommon.xsl new file mode 100755 index 000000000..7933c6906 --- /dev/null +++ b/modules/preferences/src/xslt/XCommon.xsl @@ -0,0 +1,212 @@ +<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet
+ version ="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ >
+ <!--
+ ::
+ :: Any callback must be equipped with a 'context' attribute
+ :: indicating where the rewriting triggered by the event will
+ :: occur
+ ::
+ ::::> 'here' computes context value at execution point.
+ ::
+ ::::> 'context' is used as an attribute of a callback:
+ ::
+ :: <{event-callback} {action}="{path}">
+ :: <xsl:call-template name="context"/>
+ :: [...]
+ :: </{event-callback}>
+ ::
+ ::::> org.scilab.modules.gui.utils.XCommonManager.getElementByContext
+ ::
+ -->
+
+ <xsl:template name="here">
+ <xsl:for-each select="ancestor-or-self::*">
+ <xsl:if test="not(.=/)">
+ <xsl:value-of select="count(preceding-sibling::*)+1"/>
+ <xsl:text>/</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:template>
+
+ <xsl:template name="context">
+ <xsl:attribute name="context">
+ <xsl:call-template name="here"/>
+ </xsl:attribute>
+ </xsl:template>
+
+ <!--
+ ::
+ :: Select template allow to define values of combobox within the XSL.
+ ::
+ :: <xsl:call-template name="Select">
+ :: <xsl:with-param name="among">
+ :: <option <<attr>>="<<value 1>>"/>
+ :: <option <<attr>>="<<value 2>>"/>
+ :: <option <<attr>>="<<value 3>>"/>
+ :: ...
+ :: </xsl:with-param>
+ :: </xsl:call-template>
+ ::
+ -->
+
+ <xsl:template name="Select">
+ <xsl:param name="among"/>
+ <xsl:param name="enable" select="'true'"/>
+ <xsl:variable name="list" select="nodeset($among)/*"/>
+ <xsl:variable name="attr-name">
+ <xsl:for-each select="$list[1]/@*[1]">
+ <xsl:value-of select="local-name()"/>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:variable name="attr-value" select="@*[local-name()=$attr-name]"/>
+ <Select listener="ActionListener" enable="{$enable}">
+ <actionPerformed choose="{$attr-name}">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ <xsl:for-each select="$list">
+ <option value="{@*}">
+ <xsl:if test="@*=$attr-value">
+ <xsl:attribute name="selected">selected</xsl:attribute>
+ </xsl:if>
+ </option>
+ </xsl:for-each>
+ </Select>
+ </xsl:template>
+
+ <xsl:template name="Slider">
+ <xsl:param name="among"/>
+ <xsl:variable name="list" select="nodeset($among)/*"/>
+ <xsl:variable name="attr-name">
+ <xsl:for-each select="$list[1]/@*[1]">
+ <xsl:value-of select="local-name()"/>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:variable name="attr-value" select="@*[local-name()=$attr-name]"/>
+ <Slider listener="ActionListener">
+ <actionPerformed choose="{$attr-name}">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ <xsl:for-each select="$list">
+ <option value="{@*}">
+ <xsl:if test="@*=$attr-value">
+ <xsl:attribute name="selected">selected</xsl:attribute>
+ </xsl:if>
+ </option>
+ </xsl:for-each>
+ </Slider>
+ </xsl:template>
+
+ <!--
+ ::
+ :: BooleanCheckBox template (@attr-name in {true, false})
+ ::
+ :: <xsl:call-template name="SimpleCheckBox">
+ :: <xsl:with-param name="attr-name">...</xsl:with-param>
+ :: </xsl:call-template>
+ ::
+ -->
+ <xsl:template name="BooleanCheckBox">
+ <xsl:param name="attr-name"/>
+ <xsl:param name="text" select="''"/>
+ <xsl:choose>
+ <xsl:when test="@*[local-name()=$attr-name]='true'">
+ <Checkbox checked="checked" listener="ActionListener" text="{$text}">
+ <actionPerformed set="{$attr-name}" value="false">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Checkbox>
+ </xsl:when>
+ <xsl:otherwise>
+ <Checkbox checked="unchecked" listener="ActionListener" text="{$text}">
+ <actionPerformed set="{$attr-name}" value="true">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Checkbox>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="InvertedCheckBox">
+ <xsl:param name="attr-name"/>
+ <xsl:param name="text" select="''"/>
+ <xsl:choose>
+ <xsl:when test="@*[local-name()=$attr-name]='false'">
+ <Checkbox checked="checked" listener="ActionListener" text="{$text}">
+ <actionPerformed set="{$attr-name}" value="true">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Checkbox>
+ </xsl:when>
+ <xsl:otherwise>
+ <Checkbox checked="unchecked" listener="ActionListener" text="{$text}">
+ <actionPerformed set="{$attr-name}" value="false">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Checkbox>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="BooleanRadio">
+ <xsl:param name="attr-name"/>
+ <xsl:param name="text" select="''"/>
+ <xsl:choose>
+ <xsl:when test="@*[local-name()=$attr-name]='true'">
+ <Radiobutton checked="checked" listener="ActionListener" text="{$text}">
+ <actionPerformed set="{$attr-name}" value="false">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Radiobutton>
+ </xsl:when>
+ <xsl:otherwise>
+ <Radiobutton checked="unchecked" listener="ActionListener" text="{$text}">
+ <actionPerformed set="{$attr-name}" value="true">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Radiobutton>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="InvertedRadio">
+ <xsl:param name="attr-name"/>
+ <xsl:param name="text" select="''"/>
+ <xsl:choose>
+ <xsl:when test="@*[local-name()=$attr-name]='false'">
+ <Radiobutton checked="checked" listener="ActionListener" text="{$text}">
+ <actionPerformed set="{$attr-name}" value="true">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Radiobutton>
+ </xsl:when>
+ <xsl:otherwise>
+ <Radiobutton checked="unchecked" listener="ActionListener" text="{$text}">
+ <actionPerformed set="{$attr-name}" value="false">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Radiobutton>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <!--
+ ::
+ :: Common vocabulary
+ ::
+ -->
+
+ <xsl:template match="TBD">
+ <Glue/>
+ <HBox>
+ <Glue/>
+ Implemented soon...
+ <Glue/>
+ </HBox>
+ <Glue/>
+ </xsl:template>
+
+</xsl:stylesheet>
+
diff --git a/modules/preferences/src/xslt/XConfiguration.xsl b/modules/preferences/src/xslt/XConfiguration.xsl new file mode 100755 index 000000000..e44e25e72 --- /dev/null +++ b/modules/preferences/src/xslt/XConfiguration.xsl @@ -0,0 +1,137 @@ +<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet version ="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+ <xsl:import href="XCommon.xsl"/>
+ <xsl:import href="XCommon-toolbars.xsl"/>
+ <xsl:import href="XGeneric.xsl"/>
+
+ <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
+ ::
+ :: T O P L E V E L
+ ::
+ -->
+
+ <xsl:template match="interface">
+ <ISML layout="border" height="{@height}" width="{@width}">
+ <VBox border-side="North">
+ <VSpace height="5"/>
+ </VBox>
+ <HBox border-side="West">
+ <Glue/>
+ <Panel>
+ <HSpace width="15"/>
+ </Panel>
+ <Tree listener="ActionListener">
+ <xsl:apply-templates mode="left-tree"/>
+ <actionPerformed choose="path" context="/"/>
+ </Tree>
+ <Panel>
+ <HSpace width="5"/>
+ </Panel>
+ <Glue/>
+ </HBox>
+ <HBox border-side="Center">
+ <Scroll>
+ <Panel border-side="Center">
+ <xsl:apply-templates mode="main-panel">
+ <xsl:with-param name="path" select="@path"/>
+ </xsl:apply-templates>
+ </Panel>
+ </Scroll>
+ </HBox>
+ <HBox border-side="East">
+ <Glue/>
+ <Panel>
+ <HSpace width="15"/>
+ </Panel>
+ </HBox>
+ <HBox border-side="South">
+ <VBox>
+ <Grid>
+ <Panel gridx="1" gridy="1" weightx="1"/>
+ <Button gridx="2" gridy="1" weightx="0" text="_(Default)" listener="ActionListener">
+ <actionPerformed callback="Default"/>
+ </Button>
+ <Panel gridx="3" gridy="1" weightx="0">
+ <HSpace width="10"/>
+ </Panel>
+ <Button gridx="4" gridy="1" weightx="0" text="_(Cancel)" listener="ActionListener">
+ <actionPerformed callback="Cancel"/>
+ </Button>
+ <Panel gridx="5" gridy="1" weightx="0">
+ <HSpace width="10"/>
+ </Panel>
+ <Button gridx="6" gridy="1" weightx="0" text="_(OK)" listener="ActionListener">
+ <actionPerformed callback="Ok"/>
+ </Button>
+ <Panel gridx="7" gridy="1" weightx="0">
+ <HSpace width="10"/>
+ </Panel>
+ <Button gridx="8" gridy="1" weightx="0" text="_(Apply)" listener="ActionListener">
+ <actionPerformed callback="Apply"/>
+ </Button>
+ <Panel gridx="9" gridy="1" weightx="0">
+ <HSpace width="15"/>
+ </Panel>
+ </Grid>
+ <VSpace height="10"/>
+ </VBox>
+ </HBox>
+ </ISML>
+ </xsl:template>
+
+ <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
+ ::
+ :: L E F T T R E E
+ ::
+ :: body tag are not displayed in 'left-tree' mode
+ ::
+ -->
+
+
+ <xsl:template match="*" mode="left-tree">
+ <tableNode>
+ <xsl:attribute name="name">
+ <xsl:value-of select="./@title"/>
+ </xsl:attribute>
+ <xsl:apply-templates mode="left-tree"/>
+ </tableNode>
+ </xsl:template>
+
+ <xsl:template match="toolboxes" mode="left-tree">
+ <xsl:if test="*[not(self::body)]">
+ <tableNode name="{local-name()}">
+ <xsl:apply-templates mode="left-tree"/>
+ </tableNode>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="body" mode="left-tree"/>
+
+ <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
+ ::
+ :: M A I N P A N E L :
+ ::
+ :: body tag are displayed in 'main-panel' mode iff
+ :: interface/@path == $local-path
+ ::
+ -->
+
+ <xsl:template match="body" mode="main-panel">
+ <xsl:param name="path"/>
+ <xsl:variable name="local-path">
+ <xsl:for-each select="..">
+ <xsl:call-template name="here"/>
+ </xsl:for-each>
+ </xsl:variable>
+ <!--xsl:message>
+ <xsl:value-of select="$local-path"/>::::::::<xsl:value-of select="$path"/>
+ </xsl:message-->
+ <xsl:if test="$local-path=$path">
+ <VBox path="{$path}" fill="both">
+ <xsl:apply-templates/>
+ </VBox>
+ </xsl:if>
+ </xsl:template>
+</xsl:stylesheet>
+
diff --git a/modules/preferences/src/xslt/XGeneric.xsl b/modules/preferences/src/xslt/XGeneric.xsl new file mode 100755 index 000000000..52046e925 --- /dev/null +++ b/modules/preferences/src/xslt/XGeneric.xsl @@ -0,0 +1,87 @@ +<?xml version='1.0' encoding='utf-8'?> +<xsl:stylesheet + version ="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +> + +<xsl:template match="Form"> + <Title text="{@text}"> + <Grid> + <xsl:apply-templates mode="form"/> + </Grid> + </Title> +</xsl:template> + +<xsl:template match="Entry" mode="form"> + <xsl:variable name="position" select="count(preceding-sibling::*) + 1"/> + <Label gridx="1" gridy="{$position}" text="{@text}"/> + <Entry gridx="2" gridy="{$position}" text="{@value}" listener="ActionListener"> + <actionPerformed choose="value"> + <xsl:call-template name="context"/> + </actionPerformed> + </Entry> +</xsl:template> + +<xsl:template match="Select" mode="form"> + <xsl:variable name="position" select="count(preceding-sibling::*) + 1"/> + <Label gridx="1" gridy="{$position}" text="{@text}"/> + <Select gridx="2" gridy="{$position}" listener="ActionListener"> + <actionPerformed choose="value"> + <xsl:call-template name="context"/> + </actionPerformed> + <xsl:apply-templates/> + </Select> +</xsl:template> + +<xsl:template match="Option"> + <option value="{@value}"> + <xsl:if test="@value=../@value"> + <xsl:attribute name="selected">selected</xsl:attribute> + </xsl:if> + </option> +</xsl:template> + +<xsl:template match="Color" mode="form"> + <xsl:variable name="position" select="count(preceding-sibling::*) + 1"/> + <Label gridx="1" gridy="{$position}" text="{@text}"/> + <Color gridx="2" gridy="{$position}" color="{@value}" listener="ActionListener"> + <actionPerformed choose="value"> + <xsl:call-template name="context"/> + </actionPerformed> + </Color> +</xsl:template> + +<xsl:template match="Checkbox[ @value='no']" mode="form"> + <xsl:variable name="position" select="count(preceding-sibling::*) + 1"/> + <Checkbox gridx="1" gridy="{$position}" gridwidth="2" checked="unchecked" text="{@text}" listener="ActionListener"> + <actionPerformed set="value" value="yes"> + <xsl:call-template name="context"/> + </actionPerformed> + </Checkbox> +</xsl:template> + +<xsl:template match="Checkbox[ @value='yes']" mode="form"> + <xsl:variable name="position" select="count(preceding-sibling::*) + 1"/> + <Checkbox gridx="1" gridy="{$position}" gridwidth="2" checked="checked" text="{@text}" listener="ActionListener"> + <actionPerformed set="value" value="no"> + <xsl:call-template name="context"/> + </actionPerformed> + </Checkbox> +</xsl:template> + +<!-- /////////////////////////////////////////////// --> +<!-- /// // /// /// /// /// /// /// /// /// --> +<!-- /////////////////////////////////////////////// --> + +<xsl:template match="*"> + <Glue/> + <HBox> + <Title text="{local-name()}"> + <Label text="will be implemented soon..." foreground="#0000ff"/> + </Title> + </HBox> + <Glue/> +</xsl:template> + +</xsl:stylesheet> + diff --git a/modules/preferences/src/xslt/XWizard.xsl b/modules/preferences/src/xslt/XWizard.xsl new file mode 100755 index 000000000..af0b24212 --- /dev/null +++ b/modules/preferences/src/xslt/XWizard.xsl @@ -0,0 +1,194 @@ +<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet version ="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+> <!--
+ ||
+ || I M P O R T S
+ ||
+ -->
+ <xsl:import href="XCommon.xsl"/>
+ <xsl:import href="XWizard/XWizard-any.xsl"/>
+ <xsl:import href="XWizard/XWizard-function.xsl"/>
+ <xsl:import href="XWizard/XWizard-expression.xsl"/>
+ <xsl:import href="XWizard/XWizard-xcos.xsl"/>
+
+ <!--
+ ||
+ || T E M P O R A R Y T R E E S
+ || | wrox book workaround, p.237
+ ||
+ -->
+ <xsl:variable name="imports"
+ select="document('')/xsl:stylesheet/xsl:import/@import"/>
+ <xsl:variable name="variables"
+ select="document($imports)/xsl:stylesheet/descendant::xsl-variable"/>
+
+ <!--
+ ||
+ || N A V I G A T I O N M A N A G E M E N T
+ ||
+ -->
+ <xsl:variable name="current" select="/*/*[local-name()=/*/@step]"/>
+ <xsl:variable name="next" select="$current/following-sibling::*[1]"/>
+ <xsl:variable name="prev" select="$current/preceding-sibling::*[1]"/>
+
+ <!--
+ ||
+ || T O P - L E V E L
+ ||
+ -->
+ <xsl:template match="/">
+ <ISML layout="border">
+ <VBox background="#ffffff" border-side="West" scroll="vertical">
+ <xsl:apply-templates select="*" mode="left-panel"/>
+ </VBox>
+ <Panel border-side="Center" width="640" height="420">
+ <VBox>
+ <xsl:apply-templates mode="main-panel"/>
+ </VBox>
+ </Panel>
+ <HBox border-side="South">
+ <Button text="Previous" listener="ActionListener">
+ <xsl:choose>
+ <xsl:when test="$prev">
+ <actionPerformed set="step" context="/">
+ <xsl:attribute name="value">
+ <xsl:for-each select="$prev">
+ <xsl:value-of select="local-name()"/>
+ </xsl:for-each>
+ </xsl:attribute>
+ </actionPerformed>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:attribute name="status">
+ <xsl:text>disabled</xsl:text>
+ </xsl:attribute>
+ </xsl:otherwise>
+ </xsl:choose>
+ </Button>
+ <HSpace width="5"/>
+ <Button text="Next" listener="ActionListener">
+ <xsl:choose>
+ <xsl:when test="$next">
+ <actionPerformed set="step" context="/">
+ <xsl:attribute name="value">
+ <xsl:for-each select="$next">
+ <xsl:value-of select="local-name()"/>
+ </xsl:for-each>
+ </xsl:attribute>
+ </actionPerformed>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:attribute name="status">
+ <xsl:text>disabled</xsl:text>
+ </xsl:attribute>
+ </xsl:otherwise>
+ </xsl:choose>
+ </Button>
+ <Glue/>
+ <xsl:choose>
+ <xsl:when test="user-block-wizard">
+ <Button text="Open" listener="ActionListener">
+ <actionPerformed callback="Open"/>
+ </Button>
+ </xsl:when>
+ <xsl:otherwise>
+ <Button text="New" listener="ActionListener">
+ <actionPerformed callback="New"/>
+ </Button>
+ <HSpace width="5"/>
+ <Button text="Save" listener="ActionListener">
+ <actionPerformed callback="Save"/>
+ </Button>
+ <HSpace width="5"/>
+ <Button text="Save as" listener="ActionListener">
+ <actionPerformed callback="SaveAs"/>
+ </Button>
+ <HSpace width="5"/>
+ <Button text="Ok" listener="ActionListener">
+ <actionPerformed callback="Ok"/>
+ </Button>
+ </xsl:otherwise>
+ </xsl:choose>
+ <HSpace width="5"/>
+ <Button text="Quit" listener="ActionListener">
+ <actionPerformed callback="Quit"/>
+ </Button>
+ </HBox>
+ </ISML>
+ </xsl:template>
+
+ <!--
+ ||
+ || L E F T P A N E L M A N A G E M E N T
+ ||
+ -->
+ <xsl:template match="user-block-wizard" mode="left-panel">
+ <xsl:apply-templates mode="inner-left-panel"/>
+ </xsl:template>
+
+ <xsl:template match="kind" mode="inner-left-panel">
+ <HBox>
+ <Icon src="media-playback-start.png"/>
+ <xsl:choose>
+ <xsl:when test="ancestor::user-block-wizard/@select=@name">
+ <Label
+ text="{@title}"
+ background="#0000ff"
+ foreground="#ffffff"
+ listener="MouseListener">
+ <mouseClicked callback="load" name="{@name}"/>
+ </Label>
+ </xsl:when>
+ <xsl:otherwise>
+ <Label text="{@title}">
+ <xsl:choose>
+ <xsl:when test="@name">
+ <xsl:attribute name="listener">MouseListener</xsl:attribute>
+ <mouseClicked set="select" value="{@name}" context="/"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:attribute name="foreground">#dddddd</xsl:attribute>
+ </xsl:otherwise>
+ </xsl:choose>
+ </Label>
+ </xsl:otherwise>
+ </xsl:choose>
+ <Glue/>
+ <HSpace width="25"/>
+ </HBox>
+ </xsl:template>
+
+ <xsl:template match="folder" mode="inner-left-panel">
+ <HBox>
+ <Icon src="media-playback-start.png"/><HTML><B>
+ <xsl:value-of select="@title"/>
+ <Glue/>
+ <HSpace width="25"/>
+ </HBox>
+ <HBox>
+ <HSpace width="25"/>
+ <VBox>
+ <xsl:apply-templates mode="inner-left-panel"/>
+ </VBox>
+ </HBox>
+ </xsl:template>
+
+ <!--
+ ||
+ || M E A N P A N E L M A N A G E M E N T
+ ||
+ -->
+ <xsl:template match="kind" mode="main-panel">
+ <xsl:if test="@name=ancestor::user-block-wizard/@select">
+ <Title text="{@title}">
+ <Label listener="MouseListener">
+ <xsl:attribute name="text"><xsl:apply-templates/></xsl:attribute>
+ <mouseClicked callback="load" name="{@name}"/>
+ </Label>
+ </Title>
+ </xsl:if>
+ </xsl:template>
+
+</xsl:stylesheet>
+
diff --git a/modules/preferences/src/xslt/XWizard/XWizard-any.xsl b/modules/preferences/src/xslt/XWizard/XWizard-any.xsl new file mode 100755 index 000000000..4bfe3b389 --- /dev/null +++ b/modules/preferences/src/xslt/XWizard/XWizard-any.xsl @@ -0,0 +1,342 @@ +<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet version ="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+> <!--
+ ||
+ || L E F T P A N E L M A N A G E M E N T
+ ||
+ -->
+
+ <xsl:template match="*" mode="left-panel">
+ <xsl:apply-templates mode="inner-left-panel"/>
+ <XCosPreview height="200" width="200">
+ <tableBlock>
+ <root>
+ <xsl:apply-templates select="." mode="preview"/>
+ </root>
+ </tableBlock>
+ </XCosPreview>
+ <!-- TODO -->
+ </xsl:template>
+
+ <xsl:template match="*" mode="inner-left-panel">
+ <HBox>
+ <Icon src="media-playback-start.png"/>
+ <xsl:choose>
+ <xsl:when test="local-name()=../@step">
+ <Label text="{local-name()}" background="#0000ff" foreground="#ffffff"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <Label text="{local-name()}" listener="MouseListener">
+ <mouseClicked set="step" value="{local-name()}" context="/"/>
+ </Label>
+ </xsl:otherwise>
+ </xsl:choose>
+ <Glue/>
+ <HSpace width="25"/>
+ </HBox>
+ </xsl:template>
+
+ <!--
+ ||
+ || C O M M O N M A I N P A N E L S
+ ||
+ -->
+
+ <xsl:template match="parameters" mode ="main-panel">
+ <xsl:if test="ancestor::*/@step='parameters'">
+ <xsl:for-each select="item[position()=current()/@item]">
+ <Title text="{concat('User parameter [', @name, ']:')}">
+ <VBox>
+ <HBox>
+ Variable name:
+ <Entry text="{@name}" listener="ActionListener">
+ <actionPerformed choose="name">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Entry>
+ Data-type:
+ <xsl:call-template name="Select">
+ <xsl:with-param name="among">
+ <option type="double"/>
+ <option type="integer"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </HBox>
+ <HBox>
+ Minimum:
+ <Entry text="{@min}" listener="ActionListener">
+ <actionPerformed choose="min">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Entry>
+ Test:
+ <Entry text="{@test}" listener="ActionListener">
+ <actionPerformed choose="test">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Entry>
+ Maximum:
+ <Entry text="{@max}" listener="ActionListener">
+ <actionPerformed choose="max">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Entry>
+ </HBox>
+ <HBox>
+ Description:
+ <Entry text="{@description}" listener="ActionListener">
+ <actionPerformed choose="description">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Entry>
+ </HBox>
+ <HBox>
+ Tooltip:
+ <Entry text="{@tooltip}" listener="ActionListener">
+ <actionPerformed choose="tooltip">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Entry>
+ </HBox>
+ </VBox>
+ </Title>
+ </xsl:for-each>
+ <Title text="Select parameter setup">
+ <Table mode="select" item="{@item}" size="dynamic" listener="TableListener">
+ <tableSelect choose="item">
+ <xsl:call-template name="context"/>
+ </tableSelect>
+ <tableAdd>
+ <xsl:call-template name="context"/>
+ <item name="parameter" type="double" min="0.0" max="999.9"
+ test="0.0" tooltip="tooltip" description="A parameter"/>
+ </tableAdd>
+ <tableCol title="Name" attr="name"/>
+ <tableCol title="Type" attr="type"/>
+ <tableCol title="Minimum" attr="min"/>
+ <tableCol title="Test value" attr="test"/>
+ <tableCol title="Maximum" attr="max"/>
+ <xsl:for-each select="item">
+ <tableRow name="{@name}" type="{@type}" min="{@min}" max="{@max}" test="{@test}"/>
+ </xsl:for-each>
+ </Table>
+ </Title>
+
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="interface" mode ="main-panel">
+ <xsl:if test="ancestor::*/@step='interface'">
+ <Title text="Inputs/Outputs">
+ <VBox>
+ <HBox><HTML><B>Regular Inputs<HSpace width="250"/><HTML><B>Activation Inputs
+ </HBox>
+ <HBox>
+ <xsl:for-each select="regular-inputs">
+ <Table size="dynamic" mode="cell" listener="TableListener">
+ <tableChanged>
+ <xsl:call-template name="context"/>
+ </tableChanged>
+ <tableAdd>
+ <xsl:call-template name="context"/>
+ <item name="parameter" type="double" rows="" columns=""/>
+ </tableAdd>
+ <tableDel remove="selection">
+ <xsl:call-template name="context"/>
+ </tableDel>
+ <tableCol title="Name" attr="name" editable="true"/>
+ <tableCol title="Data type" attr="type" editable="true"/>
+ <tableCol title="Rows" attr="rows" editable="true"/>
+ <tableCol title="Columns" attr="columns" editable="true"/>
+ <xsl:for-each select="item">
+ <tableRow name="{@name}" type="{@type}" rows="{@rows}" columns="{@columns}"/>
+ </xsl:for-each>
+ </Table>
+ </xsl:for-each>
+ <HSpace width="30"/>
+ <xsl:for-each select="activation-inputs">
+ <Table size="dynamic" mode="cell" listener="TableListener">
+ <tableChanged>
+ <xsl:call-template name="context"/>
+ </tableChanged>
+ <tableAdd>
+ <xsl:call-template name="context"/>
+ <item name="input"/>
+ </tableAdd>
+ <tableCol title="Name" attr="name" editable="true"/>
+ <xsl:for-each select="item">
+ <tableRow name="{@name}"/>
+ </xsl:for-each>
+ </Table>
+ </xsl:for-each>
+ </HBox>
+ <HBox><HTML><B>Regular Outputs<HSpace width="250"/><HTML><B>Activation Outputs<HSpace width="1"/>
+ </HBox>
+ <HBox>
+ <xsl:for-each select="regular-outputs">
+ <Table size="dynamic" mode="cell" listener="TableListener">
+ <tableChanged>
+ <xsl:call-template name="context"/>
+ </tableChanged>
+ <tableAdd>
+ <xsl:call-template name="context"/>
+ <item name="parameter" type="double" rows="" columns=""/>
+ </tableAdd>
+ <tableCol title="Name" attr="name" editable="true"/>
+ <tableCol title="Data type" attr="type" editable="true"/>
+ <tableCol title="Rows" attr="rows" editable="true"/>
+ <tableCol title="Columns" attr="columns" editable="true"/>
+ <xsl:for-each select="item">
+ <tableRow name="{@name}" type="{@type}" rows="{@rows}" columns="{@columns}"/>
+ </xsl:for-each>
+ </Table>
+ </xsl:for-each>
+ <HSpace width="30"/>
+ <xsl:for-each select="activation-outputs">
+ <Table size="dynamic" mode="cell" listener="TableListener">
+ <tableChanged>
+ <xsl:call-template name="context"/>
+ </tableChanged>
+ <tableAdd>
+ <xsl:call-template name="context"/>
+ <item name="String"/>
+ </tableAdd>
+ <tableCol title="Name" attr="name" editable="true"/>
+ <xsl:for-each select="item">
+ <tableRow name="{@name}"/>
+ </xsl:for-each>
+ </Table>
+ </xsl:for-each>
+ </HBox>
+ </VBox>
+ </Title>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="graphics" mode ="main-panel">
+ <xsl:if test="ancestor::*/@step='graphics'">
+ <xsl:for-each select="item[position()=current()/@item]">
+ <Title text="{concat('Current setup: ', @title)}">
+ <VBox>
+ <HBox>
+ Color:
+ <Glue/>
+ <Color color="{@color}" listener="ActionListener">
+ <actionPerformed choose="color">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Color>
+ <Glue/>
+ </HBox>
+ <xsl:if test="@family">
+ <HBox>
+ Font family:
+ <Glue/>
+ <xsl:call-template name="Select">
+ <xsl:with-param name="among">
+ <option family="Arial"/>
+ <option family="Courier New"/>
+ <option family="System"/>
+ <option family="Times New Roman"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <Glue/>
+ </HBox>
+ </xsl:if>
+ <xsl:if test="@size">
+ <HBox>
+ Font size:
+ <HSpace width="15"/>
+ <Glue/>
+ <xsl:call-template name="Select">
+ <xsl:with-param name="among">
+ <option size="6"/>
+ <option size="8"/>
+ <option size="9"/>
+ <option size="10"/>
+ <option size="11"/>
+ <option size="12"/>
+ <option size="14"/>
+ <option size="16"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <Glue/>
+ </HBox>
+ </xsl:if>
+ <xsl:if test="@face">
+ <HBox>
+ Font face:
+ <HSpace width="10"/>
+ <Glue/>
+ <xsl:call-template name="Select">
+ <xsl:with-param name="among">
+ <option face="plain"/>
+ <option face="bold"/>
+ <option face="italic"/>
+ <option face="bold italic"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <Glue/>
+ </HBox>
+ </xsl:if>
+ <xsl:if test="not(@family)">
+ <VSpace height="85"/>
+ </xsl:if>
+ </VBox>
+ </Title>
+ </xsl:for-each>
+ <VSpace height="50"/>
+ <Title text="Select graphic setup">
+ <Table mode="select" item="{@item}" listener="TableListener">
+ <tableSelect choose="item">
+ <xsl:call-template name="context"/>
+ </tableSelect>
+ <tableCol title="Kind" attr="title"/>
+ <tableCol title="Foreground" attr="color"/>
+ <tableCol title="Font family" attr="family"/>
+ <tableCol title="Font size" attr="size"/>
+ <tableCol title="Font face" attr="face"/>
+ <xsl:for-each select="item">
+ <tableRow title="{@title}" family="{@family}" size="{@size}" face="{@face}" color="{@color}"/>
+ </xsl:for-each>
+ </Table>
+ </Title>
+ <VSpace height="20"/>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="documentation" mode ="main-panel">
+ <xsl:if test="ancestor::*/@step='documentation'">
+ <Title text="Documentation">
+ <VBox>
+ <xsl:for-each select="short-description">
+ <HBox><HTML><B>Title
+ <Glue/>
+ </HBox>
+ <HBox>
+ <Entry text="{@text}" listener="ActionListener">
+ <actionPerformed choose="text">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Entry>
+ </HBox>
+ </xsl:for-each>
+ <xsl:for-each select="long-description">
+ <HBox><HTML><B>Description
+ <Glue/>
+ </HBox>
+ <Textarea listener="DocumentListener" width="350" height="300">
+ <!--documentUpdate> TODO
+ <xsl:call-template name="context"/>
+ </documentUpdate>
+ <xsl:copy-of select="node()"/ -->
+ </Textarea >
+ </xsl:for-each>
+ </VBox>
+ </Title>
+ </xsl:if>
+ </xsl:template>
+
+</xsl:stylesheet>
+
diff --git a/modules/preferences/src/xslt/XWizard/XWizard-expression.xsl b/modules/preferences/src/xslt/XWizard/XWizard-expression.xsl new file mode 100755 index 000000000..83f3abd0b --- /dev/null +++ b/modules/preferences/src/xslt/XWizard/XWizard-expression.xsl @@ -0,0 +1,71 @@ +<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet version ="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+> <!--
+ ||
+ || S P E C I F I C M A I N P A N E L S
+ ||
+ -->
+ <xsl:template match="expression" mode="preview">
+ <todo/>
+ </xsl:template>
+ <xsl:template match="expression[parent::expression]" mode ="main-panel">
+ <xsl:if test="ancestor::expression/@step='expression'">
+ <Title text="Scilab expression">
+ <VBox>
+ <HBox><HTML><B>Scilab Expressions
+ <Glue/>
+ </HBox>
+ <xsl:for-each select="outputs">
+ <Table mode="cell" location="fixed" size="dynamic" listener="TableListener">
+ <tableChanged>
+ <xsl:call-template name="context"/>
+ </tableChanged>
+ <tableAdd insert="selection">
+ <xsl:call-template name="context"/>
+ <item value="0.0"/>
+ </tableAdd>
+ <tableDel delete="selection">
+ <xsl:call-template name="context"/>
+ </tableDel>
+ <tableCol title="" width="30" attr="label"/>
+ <tableCol title="Values" attr="value" editable="true"/>
+ <xsl:for-each select="item">
+ <tableRow label="{concat('y', format-number(position(), '0'))}" value="{@value}"/>
+ </xsl:for-each>
+ </Table>
+ </xsl:for-each>
+ <HBox><HTML><B>Input test values
+ <Glue/>
+ <Button text="Execute"/>
+ </HBox>
+ <xsl:for-each select="inputs">
+ <Table mode="cell" location="fixed" size="dynamic" listener="TableListener">
+ <tableChanged>
+ <xsl:call-template name="context"/>
+ </tableChanged>
+ <tableAdd>
+ <xsl:call-template name="context"/>
+ <item value="0.0"/>
+ </tableAdd>
+ <tableCol title="" width="30" attr="label"/>
+ <tableCol title="Values" attr="value" editable="true" />
+ <xsl:for-each select="item">
+ <tableRow label="{concat('u', format-number(position(), '0'))}" value="{@value}" />
+ </xsl:for-each>
+ </Table>
+ </xsl:for-each>
+ <HBox>
+ <xsl:call-template name="BooleanCheckBox">
+ <xsl:with-param name="attr-name">zero-crossing</xsl:with-param>
+ </xsl:call-template>
+ Use zero-crossing
+ <Glue/>
+ </HBox>
+ </VBox>
+ </Title>
+ </xsl:if>
+ </xsl:template>
+
+</xsl:stylesheet>
+
diff --git a/modules/preferences/src/xslt/XWizard/XWizard-function.xsl b/modules/preferences/src/xslt/XWizard/XWizard-function.xsl new file mode 100755 index 000000000..00fbbd9d5 --- /dev/null +++ b/modules/preferences/src/xslt/XWizard/XWizard-function.xsl @@ -0,0 +1,41 @@ +<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet version ="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+> <!--
+ ||
+ || S P E C I F I C M A I N P A N E L S
+ ||
+ -->
+ <xsl:template match="function[parent::function]" mode ="main-panel">
+ <xsl:if test="ancestor::function/@step='function'">
+ <Title text="Scilab function">
+ <VBox>
+ <HBox><HTML><B>Discrete State
+ <Entry text="{@discrete-state}" listener="ActionListener">
+ <actionPerformed choose="context">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Entry>
+ </HBox>
+ <VSpace height="25"/>
+ <HBox><HTML><B>Continuous State
+ <Entry text="{@discrete-state}" listener="ActionListener">
+ <actionPerformed choose="discrete-state">
+ <xsl:call-template name="context"/>
+ </actionPerformed>
+ </Entry>
+ </HBox>
+ <VSpace height="25"/>
+ <HBox>
+ <xsl:call-template name="BooleanCheckBox">
+ <xsl:with-param name="attr-name">always-active</xsl:with-param>
+ </xsl:call-template><HTML><B>Always active
+ </HBox>
+ </VBox>
+ </Title>
+ <VSpace height="300"/>
+ </xsl:if>
+ </xsl:template>
+
+</xsl:stylesheet>
+
diff --git a/modules/preferences/src/xslt/XWizard/XWizard-xcos.xsl b/modules/preferences/src/xslt/XWizard/XWizard-xcos.xsl new file mode 100755 index 000000000..eadc8b799 --- /dev/null +++ b/modules/preferences/src/xslt/XWizard/XWizard-xcos.xsl @@ -0,0 +1,15 @@ +<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet version ="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+> <!--
+ ||
+ || S P E C I F I C M A I N P A N E L S
+ ||
+ -->
+ <xsl:template match="xcos" mode="preview">
+ <xsl:for-each select="interface/regular-inputs/item">
+ <xsl:value-of select="@columns"/>
+ </xsl:for-each>
+ </xsl:template>
+</xsl:stylesheet>
+
|