<path value="$SCILAB/modules/scinotes/.libs"/>
<path value="$SCILAB/modules/commons/.libs"/>
<path value="$SCILAB/modules/gui/.libs"/>
+<path value="$SCILAB/modules/ui_data/.libs"/>
<path value="$SCILAB/.libs"/>
<!-- Default path to the JNI classes under some Linux (JoGL under Debian for example) -->
images/icons/16x16/actions/go-bottom.png \
images/icons/16x16/actions/go-top.png \
images/icons/16x16/actions/view-refresh.png \
+images/icons/16x16/actions/SizeColumnsToFit.png \
+images/icons/16x16/actions/long.png \
+images/icons/16x16/actions/longe.png \
+images/icons/16x16/actions/short.png \
+images/icons/16x16/actions/shorte.png \
+images/icons/16x16/actions/variable-new.png \
images/icons/16x16/search/folder.png \
images/icons/16x16/search/file.png \
images/icons/16x16/search/line-found.png \
images/icons/16x16/filebrowser/text-x-generic.png \
images/icons/16x16/filebrowser/text-xml.png \
images/icons/16x16/filebrowser/user-home.png \
+images/icons/64x64/plot2d.png \
+images/icons/64x64/Matplot.png \
+images/icons/64x64/grayplot.png \
+images/icons/64x64/Sgrayplot.png \
+images/icons/64x64/champ.png \
+images/icons/64x64/histplot.png \
+images/icons/64x64/mesh.png \
+images/icons/64x64/surf.png \
+images/icons/64x64/hist3d.png \
images/icons/aboutscilab.png \
images/icons/accessories-text-editor.png \
images/icons/applications-system.png \
images/icons/16x16/actions/go-bottom.png \
images/icons/16x16/actions/go-top.png \
images/icons/16x16/actions/view-refresh.png \
+images/icons/16x16/actions/SizeColumnsToFit.png \
+images/icons/16x16/actions/long.png \
+images/icons/16x16/actions/longe.png \
+images/icons/16x16/actions/short.png \
+images/icons/16x16/actions/shorte.png \
+images/icons/16x16/actions/variable-new.png \
images/icons/16x16/search/folder.png \
images/icons/16x16/search/file.png \
images/icons/16x16/search/line-found.png \
images/icons/16x16/filebrowser/text-x-generic.png \
images/icons/16x16/filebrowser/text-xml.png \
images/icons/16x16/filebrowser/user-home.png \
+images/icons/64x64/plot2d.png \
+images/icons/64x64/Matplot.png \
+images/icons/64x64/grayplot.png \
+images/icons/64x64/Sgrayplot.png \
+images/icons/64x64/champ.png \
+images/icons/64x64/histplot.png \
+images/icons/64x64/mesh.png \
+images/icons/64x64/surf.png \
+images/icons/64x64/hist3d.png \
images/icons/aboutscilab.png \
images/icons/accessories-text-editor.png \
images/icons/applications-system.png \
src/jni/EditVar.cpp \
src/jni/FileBrowser.cpp
-UI_DATA_C_SOURCES =
+UI_DATA_C_SOURCES = src/jni/ui_data_wrap.c \
+ src/c/PutScilabVariable.c
UI_DATA_CPP_SOURCES = src/cpp/UpdateBrowseVar.cpp \
src/cpp/FileBrowserChDir.cpp
GATEWAY_C_SOURCES = sci_gateway/c/gw_ui_data.c
+
GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_editvar.cpp \
sci_gateway/cpp/sci_browsevar.cpp \
- sci_gateway/cpp/sci_filebrowser.cpp
+ sci_gateway/cpp/sci_filebrowser.cpp \
+ sci_gateway/cpp/sci_updatebrowsevar.cpp
libsciui_data_la_CFLAGS= $(JAVA_JNI_INCLUDE) \
-I$(top_srcdir)/libs/MALLOC/includes/ \
"$(DESTDIR)$(libsciui_data_la_iconsdir)"
LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkglib_LTLIBRARIES)
libsciui_data_algo_la_LIBADD =
-am__objects_1 =
+am__objects_1 = libsciui_data_algo_la-ui_data_wrap.lo \
+ libsciui_data_algo_la-PutScilabVariable.lo
am__objects_2 = libsciui_data_algo_la-BrowseVar.lo \
libsciui_data_algo_la-EditVar.lo \
libsciui_data_algo_la-FileBrowser.lo
am__objects_5 = libsciui_data_la-gw_ui_data.lo
am__objects_6 = libsciui_data_la-sci_editvar.lo \
libsciui_data_la-sci_browsevar.lo \
- libsciui_data_la-sci_filebrowser.lo
+ libsciui_data_la-sci_filebrowser.lo \
+ libsciui_data_la-sci_updatebrowsevar.lo
am_libsciui_data_la_OBJECTS = $(am__objects_5) $(am__objects_6)
libsciui_data_la_OBJECTS = $(am_libsciui_data_la_OBJECTS)
libsciui_data_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
src/jni/EditVar.cpp \
src/jni/FileBrowser.cpp
-UI_DATA_C_SOURCES =
+UI_DATA_C_SOURCES = src/jni/ui_data_wrap.c \
+ src/c/PutScilabVariable.c
+
UI_DATA_CPP_SOURCES = src/cpp/UpdateBrowseVar.cpp \
src/cpp/FileBrowserChDir.cpp
GATEWAY_C_SOURCES = sci_gateway/c/gw_ui_data.c
GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_editvar.cpp \
sci_gateway/cpp/sci_browsevar.cpp \
- sci_gateway/cpp/sci_filebrowser.cpp
+ sci_gateway/cpp/sci_filebrowser.cpp \
+ sci_gateway/cpp/sci_updatebrowsevar.cpp
libsciui_data_la_CFLAGS = $(JAVA_JNI_INCLUDE) \
-I$(top_srcdir)/libs/MALLOC/includes/ \
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-EditVar.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-FileBrowser.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-FileBrowserChDir.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-PutScilabVariable.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-UpdateBrowseVar.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_algo_la-ui_data_wrap.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_disable_la-noui_data.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_la-gw_ui_data.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_la-sci_browsevar.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_la-sci_editvar.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_la-sci_filebrowser.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciui_data_la-sci_updatebrowsevar.Plo@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+libsciui_data_algo_la-ui_data_wrap.lo: src/jni/ui_data_wrap.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(libsciui_data_algo_la_CFLAGS) $(CFLAGS) -MT libsciui_data_algo_la-ui_data_wrap.lo -MD -MP -MF $(DEPDIR)/libsciui_data_algo_la-ui_data_wrap.Tpo -c -o libsciui_data_algo_la-ui_data_wrap.lo `test -f 'src/jni/ui_data_wrap.c' || echo '$(srcdir)/'`src/jni/ui_data_wrap.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libsciui_data_algo_la-ui_data_wrap.Tpo $(DEPDIR)/libsciui_data_algo_la-ui_data_wrap.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/jni/ui_data_wrap.c' object='libsciui_data_algo_la-ui_data_wrap.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(libsciui_data_algo_la_CFLAGS) $(CFLAGS) -c -o libsciui_data_algo_la-ui_data_wrap.lo `test -f 'src/jni/ui_data_wrap.c' || echo '$(srcdir)/'`src/jni/ui_data_wrap.c
+
+libsciui_data_algo_la-PutScilabVariable.lo: src/c/PutScilabVariable.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(libsciui_data_algo_la_CFLAGS) $(CFLAGS) -MT libsciui_data_algo_la-PutScilabVariable.lo -MD -MP -MF $(DEPDIR)/libsciui_data_algo_la-PutScilabVariable.Tpo -c -o libsciui_data_algo_la-PutScilabVariable.lo `test -f 'src/c/PutScilabVariable.c' || echo '$(srcdir)/'`src/c/PutScilabVariable.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libsciui_data_algo_la-PutScilabVariable.Tpo $(DEPDIR)/libsciui_data_algo_la-PutScilabVariable.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/c/PutScilabVariable.c' object='libsciui_data_algo_la-PutScilabVariable.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_algo_la_CPPFLAGS) $(CPPFLAGS) $(libsciui_data_algo_la_CFLAGS) $(CFLAGS) -c -o libsciui_data_algo_la-PutScilabVariable.lo `test -f 'src/c/PutScilabVariable.c' || echo '$(srcdir)/'`src/c/PutScilabVariable.c
+
libsciui_data_disable_la-noui_data.lo: src/noui_data/noui_data.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libsciui_data_disable_la_CFLAGS) $(CFLAGS) -MT libsciui_data_disable_la-noui_data.lo -MD -MP -MF $(DEPDIR)/libsciui_data_disable_la-noui_data.Tpo -c -o libsciui_data_disable_la-noui_data.lo `test -f 'src/noui_data/noui_data.c' || echo '$(srcdir)/'`src/noui_data/noui_data.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libsciui_data_disable_la-noui_data.Tpo $(DEPDIR)/libsciui_data_disable_la-noui_data.Plo
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciui_data_la-sci_filebrowser.lo `test -f 'sci_gateway/cpp/sci_filebrowser.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_filebrowser.cpp
+libsciui_data_la-sci_updatebrowsevar.lo: sci_gateway/cpp/sci_updatebrowsevar.cpp
+@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsciui_data_la-sci_updatebrowsevar.lo -MD -MP -MF $(DEPDIR)/libsciui_data_la-sci_updatebrowsevar.Tpo -c -o libsciui_data_la-sci_updatebrowsevar.lo `test -f 'sci_gateway/cpp/sci_updatebrowsevar.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_updatebrowsevar.cpp
+@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/libsciui_data_la-sci_updatebrowsevar.Tpo $(DEPDIR)/libsciui_data_la-sci_updatebrowsevar.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='sci_gateway/cpp/sci_updatebrowsevar.cpp' object='libsciui_data_la-sci_updatebrowsevar.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciui_data_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciui_data_la-sci_updatebrowsevar.lo `test -f 'sci_gateway/cpp/sci_updatebrowsevar.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_updatebrowsevar.cpp
+
mostlyclean-libtool:
-rm -f *.lo
UI_DATA_IMPEXP int sci_editvar(char* fname, unsigned long l);
UI_DATA_IMPEXP int sci_browsevar(char* fname, unsigned long l);
UI_DATA_IMPEXP int sci_filebrowser(char* fname, unsigned long l);
+UI_DATA_IMPEXP int sci_updatebrowsevar(char* fname, unsigned long l);
/*--------------------------------------------------------------------------*/
#endif /* __GW_UI_DATA__ */
/*--------------------------------------------------------------------------*/
--- /dev/null
+/*
+* 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-en.txt
+*
+*/
+
+/*------------------------------------------------------------------------*/
+#ifndef __UI_DATA_C_H__
+#define __UI_DATA_C_H__
+/*------------------------------------------------------------------------*/
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*------------------------------------------------------------------------*/
+ void putScilabVariable(char * name, char ** lines, int rows, int cols);
+ char * getUnnamedVariable();
+/*------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+/*------------------------------------------------------------------------*/
+#endif /* __UI_DATA_C_H__ */
+/*------------------------------------------------------------------------*/
{
{sci_editvar, "editvar"},
{sci_browsevar, "browsevar"},
- {sci_filebrowser, "filebrowser"}
+ {sci_filebrowser, "filebrowser"},
+ {sci_updatebrowsevar, "updatebrowsevar"}
};
/*--------------------------------------------------------------------------*/
int gw_ui_data(void)
* Copyright (C) 2010 - DIGITEO - Allan CORNET
* Copyright (C) 2010 - DIGITEO - Allan SIMON
* Copyright (C) 2010 - DIGITEO - Bruno JOFRET
+ * 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
#include <iostream>
#include "EditVar.hxx"
+#include "GiwsException.hxx"
+//#include "ScilabToJava.hxx"
extern "C"
{
#include "sciprint.h"
#include "getScilabJavaVM.h"
#include "localization.h"
+#include <time.h>
}
using namespace org_scilab_modules_ui_data;
/*--------------------------------------------------------------------------*/
-int sci_editvar(char *fname,unsigned long fname_len)
+template <typename T, typename U>
+T** wrap(U * x, int r, int c)
{
- CheckRhs(1,1); /* TODO change this in the future */
- CheckLhs(0,1);
+ T ** xx = new T*[r];
+ for (int i = 0; i < r; i++)
+ {
+ xx[i] = new T[c];
+ for (int j = 0; j < c; j++)
+ {
+ xx[i][j] = static_cast<T>(x[j * r + i]);
+ }
+ }
+
+ return xx;
+}
+/*--------------------------------------------------------------------------*/
+/* For example if the matrix is [1 2 0 0 0;0 1 2 0 0;0 2 1 3 0 0;0 0 0 0 0;0 0 0 0 1], then
+ r=5, c=5, nbItem=8, nbItemRow=[2 2 3 0 1], colPos=[1 2 2 3 2 3 4 5] and x=[1 2 1 2 2 1 3 1] */
+double ** wrapSparse(int nbItem, int * nbItemRow, int * colPos, int r, int c, double * x)
+{
+ double ** xx = new double*[r];
+ int prev = 0;
+ for (int i = 0; i < r; i++)
+ {
+ xx[i] = new double[c];
+ memset(xx[i], 0, c * sizeof(double));
+ for (int j = 0; j < nbItemRow[i]; j++) {
+ xx[i][colPos[prev + j] - 1] = x[prev + j];
+ }
+ prev += nbItemRow[i];
+ }
+
+ return xx;
+}
+/*--------------------------------------------------------------------------*/
+/* boolean version */
+int ** wrapSparse(int nbItem, int * nbItemRow, int * colPos, int r, int c)
+{
+ int ** xx = new int*[r];
+ int prev = 0;
+ for (int i = 0; i < r; i++)
+ {
+ xx[i] = new int[c];
+ memset(xx[i], 0, c * sizeof(int));
+ for (int j = 0; j < nbItemRow[i]; j++) {
+ xx[i][colPos[prev + j] - 1] = 1;
+ }
+ prev += nbItemRow[i];
+ }
+
+ return xx;
+}
+/*--------------------------------------------------------------------------*/
+template <typename T>
+void clearWrap(T ** x, int r)
+{
+ for (int i = 0; i < r; i++)
+ {
+ delete [] x[i];
+ }
+
+ delete x;
+}
+/*--------------------------------------------------------------------------*/
+int sci_editvar(char * fname, unsigned long fname_len)
+{
+ CheckRhs(1, 4); /* TODO change this in the future */
+ CheckLhs(0, 1);
+
SciErr sciErr;
int m1 = 0, n1 = 0;
- int *piAddr = NULL;
+ int * piAddr = NULL;
int iType = 0;
int iCols = 0;
int iRows = 0;
- int* piBool = NULL;
- int** ppiBool = NULL;
+ int * piBool = NULL;
+ int ** ppiBool = NULL;
- char* piInt8 = NULL;
- char** ppiInt8 = NULL;
+ char * piInt8 = NULL;
+ char ** ppiInt8 = NULL;
- unsigned char* piUInt8 = NULL;
- short** ppiUInt8 = NULL;
+ unsigned char * piUInt8 = NULL;
+ short ** ppiUInt8 = NULL;
- short* piInt16 = NULL;
- short** ppiInt16 = NULL;
+ short * piInt16 = NULL;
+ short ** ppiInt16 = NULL;
- unsigned short* piUInt16 = NULL;
- int** ppiUInt16 = NULL;
+ unsigned short * piUInt16 = NULL;
+ int ** ppiUInt16 = NULL;
- int* piInt32 = NULL;
- int** ppiInt32 = NULL;
+ int * piInt32 = NULL;
+ int ** ppiInt32 = NULL;
- unsigned int* piUInt32 = NULL;
- long long int** ppiUInt32 = NULL;
+ unsigned int * piUInt32 = NULL;
+ long long int ** ppiUInt32 = NULL;
int iComplex = 0;
- double *pdblReal = NULL;
- double *pdblImg = NULL;
- double **ppdblRealMatrix = NULL;
- double **ppdblImgMatrix = NULL;
+ double * pdblReal = NULL;
+ double * pdblImg = NULL;
+ double ** ppdblRealMatrix = NULL;
+ double ** ppdblImgMatrix = NULL;
- char** pstData = NULL;
- int* piLen = NULL;
- char ***ppstData = NULL;
+ char ** pstData = NULL;
+ int * piLen = NULL;
+ char *** ppstData = NULL;
- int *piAddressVarOne = NULL;
- char *pStVarOne = NULL;
+ int * piAddressVarOne = NULL;
+ char * pStVarOne = NULL;
int lenStVarOne = 0;
- /*get input data*/
- if(Rhs != 1)
+ int * addr = NULL;
+ double * rowsIndex = NULL;
+ int nbRowsIndex = 0;
+ double * colsIndex = NULL;
+ int nbColsIndex = 0;
+
+ int piNbItem = 0;
+ int * piNbItemRow = NULL;
+ int * piColPos = NULL;
+
+ if (Rhs == 3)
{
- Scierror(999,_("%s: Wrong number of input argument(s): %d expected.\n"), fname, 1);
+ Scierror(999,_("%s: Wrong number of input argument(s): 1, 2 or 4 expected.\n"), fname);
return 0;
}
/* get address */
sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
/* get dimensions */
sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, NULL, NULL);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
/* TODO maybe allow vectors in case someone wants to edit several variables in the same time? */
- if(m1 != 1 || n1 != 1)
+ if (m1 != 1 || n1 != 1)
{
Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1);
return 0;
/* get lengths */
sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, &lenStVarOne, NULL);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
/* get variable name to edit */
sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, &lenStVarOne, &pStVarOne);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
FREE(pStVarOne);
printError(&sciErr, 0);
return 0;
}
- if(strcmp(pStVarOne, "ans") == 0)
+ if (strcmp(pStVarOne, "ans") == 0)
{
- Scierror(999,_("%s: ans cannot be edited.\n"), fname);
+ Scierror(999, _("%s: ans cannot be edited.\n"), fname);
FREE(pStVarOne);
return 0;
}
/* get address of the variable*/
sciErr = getVarAddressFromName(pvApiCtx, pStVarOne, &piAddr);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
- Scierror(4,_("%s: Undefined variable %s.\n"), fname, pStVarOne);
+ Scierror(4, _("%s: Undefined variable %s.\n"), fname, pStVarOne);
FREE(pStVarOne);
return 0;
}
+ if (Rhs == 1)
+ {
+ /* get address of the variable*/
+ sciErr = getVarAddressFromName(pvApiCtx, pStVarOne, &piAddr);
+ if(sciErr.iErr)
+ {
+ Scierror(4, _("%s: Undefined variable %s.\n"), fname, pStVarOne);
+ FREE(pStVarOne);
+ return 0;
+ }
+ }
+ else
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ FREE(pStVarOne);
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ if (Rhs == 4)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &addr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ FREE(pStVarOne);
+ return 0;
+ }
+
+ if (!isDoubleType(pvApiCtx, addr))
+ {
+ Scierror(999,_("%s: Wrong type for input argument #%d: Double expected.\n"), fname, 3);
+ FREE(pStVarOne);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, addr, &iRows, &iCols, &rowsIndex);
+ if (sciErr.iErr)
+ {
+ FREE(pStVarOne);
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ nbRowsIndex = iRows * iCols;
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &addr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ FREE(pStVarOne);
+ return 0;
+ }
+
+ if (!isDoubleType(pvApiCtx, addr))
+ {
+ Scierror(999,_("%s: Wrong type for input argument #%d: Double expected.\n"), fname, 4);
+ FREE(pStVarOne);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, addr, &iRows, &iCols, &colsIndex);
+ if (sciErr.iErr)
+ {
+ FREE(pStVarOne);
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ nbColsIndex = iRows * iCols;
+ }
+
+ //org_modules_commons::ScilabToJava::sendVariable(std::string(pStVarOne), true, pvApiCtx);
+
/* get type of the named variable */
sciErr = getVarType(pvApiCtx, piAddr, &iType);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
FREE(pStVarOne);
printError(&sciErr, 0);
iComplex = isVarComplex(pvApiCtx, piAddr);
/* check complexity */
- if(iComplex)
+ if (iComplex)
{
/* get size and data from Scilab memory */
sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal, &pdblImg);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
FREE(pStVarOne);
printError(&sciErr, 0);
return 0;
}
- ppdblRealMatrix = new double*[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppdblRealMatrix[i] = &pdblReal[i * iCols];
- }
-
- ppdblImgMatrix = new double*[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppdblImgMatrix[i] = &pdblImg[i * iCols];
- }
+ ppdblRealMatrix = wrap<double, double>(pdblReal, iRows, iCols);
+ ppdblImgMatrix = wrap<double, double>(pdblImg, iRows, iCols);
- /* Launch Java Variable Editor through JNI */
try
{
- EditVar::openVariableEditorComplex(getScilabJavaVM(),
- ppdblRealMatrix,
- iRows,
- iCols,
- ppdblImgMatrix,
- iRows,
- iCols,
- pStVarOne);
- } catch (GiwsException::JniCallMethodException ex1)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
- } catch (GiwsException::JniBadAllocException ex2)
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ /* Launch Java Variable Editor through JNI */
+ EditVar::openVariableEditorComplex(getScilabJavaVM(),
+ ppdblRealMatrix,
+ iRows,
+ iCols,
+ ppdblImgMatrix,
+ iRows,
+ iCols,
+ pStVarOne);
+ }
+ else
+ {
+ /* Launch Java Variable Editor through JNI */
+ EditVar::refreshVariableEditorComplex(getScilabJavaVM(),
+ ppdblRealMatrix,
+ iRows,
+ iCols,
+ ppdblImgMatrix,
+ iRows,
+ iCols,
+ rowsIndex,
+ nbRowsIndex,
+ colsIndex,
+ nbColsIndex,
+ pStVarOne);
+ }
+ }
+ catch (const GiwsException::JniException & e)
{
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
}
- delete(ppdblRealMatrix);
- delete(ppdblImgMatrix);
+ clearWrap<double>(ppdblRealMatrix, iRows);
+ clearWrap<double>(ppdblImgMatrix, iRows);
}
else
{
/* get size and data from Scilab memory */
sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
FREE(pStVarOne);
printError(&sciErr, 0);
* we need this to make the links between the API (which return a double*)
* and the JNI which needs a double**
*/
- ppdblRealMatrix = new double*[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppdblRealMatrix[i] = &pdblReal[i * iCols];
- }
+ ppdblRealMatrix = wrap<double, double>(pdblReal, iRows, iCols);
/* Launch Java Variable Editor through JNI */
try
{
- EditVar::openVariableEditorDouble(getScilabJavaVM(), ppdblRealMatrix, iRows, iCols, pStVarOne);
- } catch (GiwsException::JniCallMethodException ex1)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
- } catch (GiwsException::JniBadAllocException ex2)
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorDouble(getScilabJavaVM(), ppdblRealMatrix, iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorDouble(getScilabJavaVM(), ppdblRealMatrix, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
+ }
+ catch (const GiwsException::JniException & e)
{
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
}
- delete(ppdblRealMatrix);
+ clearWrap<double>(ppdblRealMatrix, iRows);
}
break;
//fisrt call to retrieve dimensions
sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
FREE(pStVarOne);
printError(&sciErr, 0);
//second call to retrieve length of each string
sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
FREE(pStVarOne);
FREE(piLen);
}
//third call to retrieve data
sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
FREE(pStVarOne);
FREE(piLen);
* we need this to make the links between the API (which return a char**)
* and the JNI which needs a char***
*/
- ppstData = new char**[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppstData[i] = &pstData[i * iCols];
- }
+ ppstData = wrap<char *, char *>(pstData, iRows, iCols);
+
/* Launch Java Variable Editor through JNI */
try
{
- EditVar::openVariableEditorString(getScilabJavaVM(), ppstData, iRows, iCols, pStVarOne);
- } catch (GiwsException::JniCallMethodException ex1)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
- } catch (GiwsException::JniBadAllocException ex2)
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorString(getScilabJavaVM(), ppstData, iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorString(getScilabJavaVM(), ppstData, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
+ }
+ catch (const GiwsException::JniException & e)
{
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
}
FREE(piLen);
freeArrayOfString(pstData, iRows * iCols);
- delete(ppstData);
+
+ clearWrap<char *>(ppstData, iRows);
break;
case sci_boolean :
//get size and data from Scilab memory
sciErr = getMatrixOfBoolean(pvApiCtx, piAddr, &iRows, &iCols, &piBool);
- if(sciErr.iErr)
+ if (sciErr.iErr)
{
FREE(pStVarOne);
printError(&sciErr, 0);
* we need this to make the links between the API (which return a int*)
* and the JNI which needs a int**
*/
- ppiBool = new int*[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppiBool[i] = &piBool[i * iCols];
- }
+ ppiBool = wrap<int, int>(piBool, iRows, iCols);
+
/* Launch Java Variable Editor through JNI */
try
{
- EditVar::openVariableEditorBoolean(getScilabJavaVM(), ppiBool, iRows, iCols, pStVarOne);
- } catch (GiwsException::JniCallMethodException ex1)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
- } catch (GiwsException::JniBadAllocException ex2)
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorBoolean(getScilabJavaVM(), ppiBool, iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorBoolean(getScilabJavaVM(), ppiBool, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
+ }
+ catch (const GiwsException::JniException & e)
{
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
}
- delete(ppiBool);
+ clearWrap<int>(ppiBool, iRows);
break;
printError(&sciErr, 0);
return -1;
}
- ppiInt8 = new char*[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppiInt8[i] = &piInt8[i * iCols];
- }
+
+ ppiInt8 = wrap<char, char>(piInt8, iRows, iCols);
/* Launch Java Variable Editor through JNI */
try
{
- EditVar::openVariableEditorInteger8(getScilabJavaVM(), reinterpret_cast<byte**>(ppiInt8), iRows, iCols, pStVarOne);
- } catch (GiwsException::JniCallMethodException ex1)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
- } catch (GiwsException::JniBadAllocException ex2)
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorInteger8(getScilabJavaVM(), reinterpret_cast<byte**>(ppiInt8), iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorInteger8(getScilabJavaVM(), reinterpret_cast<byte**>(ppiInt8), iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
+ }
+ catch (const GiwsException::JniException & e)
{
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
}
- delete(ppiInt8);
+ clearWrap<char>(ppiInt8, iRows);
break;
return -1;
}
- ppiUInt8 = new short*[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppiUInt8[i] = new short[iCols];
- for (int j = 0; j < iCols; ++j)
- {
- ppiUInt8[i][j] = piUInt8[i * iCols + j];
- }
- }
+ ppiUInt8 = wrap<short, unsigned char>(piUInt8, iRows, iCols);
/* Launch Java Variable Editor through JNI */
try
{
- EditVar::openVariableEditorUInteger8(getScilabJavaVM(), ppiUInt8, iRows, iCols, pStVarOne);
- } catch (GiwsException::JniCallMethodException ex1)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
- } catch (GiwsException::JniBadAllocException ex2)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorUInteger8(getScilabJavaVM(), ppiUInt8, iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorUInteger8(getScilabJavaVM(), ppiUInt8, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
}
-
- for (int i = 0; i < iRows; ++i)
+ catch (const GiwsException::JniException & e)
{
- delete(ppiUInt8[i]);
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
}
- delete(ppiUInt8);
+
+ clearWrap<short>(ppiUInt8, iRows);
break;
printError(&sciErr, 0);
return -1;
}
- ppiInt16 = new short*[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppiInt16[i] = &piInt16[i * iCols];
- }
+
+ ppiInt16 = wrap<short, short>(piInt16, iRows, iCols);
/* Launch Java Variable Editor through JNI */
try
{
- EditVar::openVariableEditorInteger16(getScilabJavaVM(), ppiInt16, iRows, iCols, pStVarOne);
- } catch (GiwsException::JniCallMethodException ex1)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
- } catch (GiwsException::JniBadAllocException ex2)
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorInteger16(getScilabJavaVM(), ppiInt16, iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorInteger16(getScilabJavaVM(), ppiInt16, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
+ }
+ catch (const GiwsException::JniException & e)
{
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
}
- delete(ppiInt16);
+ clearWrap<short>(ppiInt16, iRows);
break;
return -1;
}
- ppiUInt16 = new int*[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppiUInt16[i] = new int[iCols];
- for (int j = 0; j < iCols; ++j)
- {
- ppiUInt16[i][j] = piUInt16[i * iCols + j];
- }
- }
+ ppiUInt16 = wrap<int, unsigned short>(piUInt16, iRows, iCols);
/* Launch Java Variable Editor through JNI */
try
{
- EditVar::openVariableEditorUInteger16(getScilabJavaVM(), ppiUInt16, iRows, iCols, pStVarOne);
- } catch (GiwsException::JniCallMethodException ex1)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
- } catch (GiwsException::JniBadAllocException ex2)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorUInteger16(getScilabJavaVM(), ppiUInt16, iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorUInteger16(getScilabJavaVM(), ppiUInt16, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
}
-
- for (int i = 0; i < iRows; ++i)
+ catch (const GiwsException::JniException & e)
{
- delete(ppiUInt16[i]);
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
}
- delete(ppiUInt16);
+
+ clearWrap<int>(ppiUInt16, iRows);
break;
printError(&sciErr, 0);
return -1;
}
- ppiInt32 = new int*[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppiInt32[i] = &piInt32[i * iCols];
- }
+
+ ppiInt32 = wrap<int>(piInt32, iRows, iCols);
/* Launch Java Variable Editor through JNI */
try
{
- EditVar::openVariableEditorInteger32(getScilabJavaVM(), ppiInt32, iRows, iCols, pStVarOne);
- } catch (GiwsException::JniCallMethodException ex1)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
- } catch (GiwsException::JniBadAllocException ex2)
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorInteger32(getScilabJavaVM(), ppiInt32, iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorInteger32(getScilabJavaVM(), ppiInt32, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
+ }
+ catch (const GiwsException::JniException & e)
{
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
}
- delete(ppiInt32);
+ clearWrap<int>(ppiInt32, iRows);
break;
return -1;
}
- ppiUInt32 = new long long int*[iRows];
- for (int i = 0; i < iRows; ++i)
- {
- ppiUInt32[i] = new long long int[iCols];
- for (int j = 0; j < iCols; ++j)
- {
- ppiUInt32[i][j] = piUInt32[i * iCols + j];
- }
- }
+ ppiUInt32 = wrap<long long int, unsigned int>(piUInt32, iRows, iCols);
/* Launch Java Variable Editor through JNI */
try
{
- EditVar::openVariableEditorUInteger32(getScilabJavaVM(), ppiUInt32, iRows, iCols, pStVarOne);
- } catch (GiwsException::JniCallMethodException ex1)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
- } catch (GiwsException::JniBadAllocException ex2)
- {
- Scierror(999, _("%s: Java memory problem, cannot edit %s\n"), fname, pStVarOne);
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorUInteger32(getScilabJavaVM(), ppiUInt32, iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorUInteger32(getScilabJavaVM(), ppiUInt32, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
}
-
- for (int i = 0; i < iRows; ++i)
+ catch (const GiwsException::JniException & e)
{
- delete(ppiUInt32[i]);
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
}
- delete(ppiUInt32);
+
+ clearWrap<long long int>(ppiUInt32, iRows);
break;
break;
+ case sci_boolean_sparse :
+ sciErr = getBooleanSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &piNbItem, &piNbItemRow, &piColPos);
+ if (sciErr.iErr)
+ {
+ FREE(pStVarOne);
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ppiBool = wrapSparse(piNbItem, piNbItemRow, piColPos, iRows, iCols);
+
+ /* Launch Java Variable Editor through JNI */
+ try
+ {
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorBooleanSparse(getScilabJavaVM(), ppiBool, iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorBooleanSparse(getScilabJavaVM(), ppiBool, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
+ }
+ catch (const GiwsException::JniException & e)
+ {
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
+ }
+
+ clearWrap<int>(ppiBool, iRows);
+ break;
+ case sci_sparse :
+ if (isVarComplex(pvApiCtx, piAddr))
+ {
+ sciErr = getComplexSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &piNbItem, &piNbItemRow, &piColPos, &pdblReal, &pdblImg);
+ if (sciErr.iErr)
+ {
+ FREE(pStVarOne);
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ppdblRealMatrix = wrapSparse(piNbItem, piNbItemRow, piColPos, iRows, iCols, pdblReal);
+ ppdblImgMatrix = wrapSparse(piNbItem, piNbItemRow, piColPos, iRows, iCols, pdblImg);
+
+ /* Launch Java Variable Editor through JNI */
+ try
+ {
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorComplexSparse(getScilabJavaVM(), ppdblRealMatrix, iRows, iCols, ppdblImgMatrix, iRows, iCols, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorComplexSparse(getScilabJavaVM(), ppdblRealMatrix, iRows, iCols, ppdblImgMatrix, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
+ }
+ catch (const GiwsException::JniException & e)
+ {
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
+ }
+
+ clearWrap<double>(ppdblRealMatrix, iRows);
+ clearWrap<double>(ppdblImgMatrix, iRows);
+ }
+ else
+ {
+ sciErr = getSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &piNbItem, &piNbItemRow, &piColPos, &pdblReal);
+ if (sciErr.iErr)
+ {
+ FREE(pStVarOne);
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ppdblRealMatrix = wrapSparse(piNbItem, piNbItemRow, piColPos, iRows, iCols, pdblReal);
+
+ /* Launch Java Variable Editor through JNI */
+ try
+ {
+ if (nbRowsIndex == 0 || nbColsIndex == 0)
+ {
+ EditVar::openVariableEditorSparse(getScilabJavaVM(), ppdblRealMatrix, iCols, iRows, pStVarOne);
+ }
+ else
+ {
+ EditVar::refreshVariableEditorSparse(getScilabJavaVM(), ppdblRealMatrix, iRows, iCols, rowsIndex, nbRowsIndex, colsIndex, nbColsIndex, pStVarOne);
+ }
+ }
+ catch (const GiwsException::JniException & e)
+ {
+ Scierror(999, _("%s: Java exception arised:\n%s\n"), fname, e.what());
+ }
+
+ clearWrap<double>(ppdblRealMatrix, iRows);
+ }
+ break;
default:
Scierror(42, _("%s: Type not handle yet"), fname);
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - DIGITEO - Allan CORNET
+ * Copyright (C) 2010 - DIGITEO - Bruno JOFRET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+extern "C"
+{
+#include "UpdateBrowseVar.h"
+#include "gw_ui_data.h"
+#include "BOOL.h"
+#include "stack-c.h"
+#include "stackinfo.h"
+#include "api_scilab.h"
+#include "Scierror.h"
+}
+/*--------------------------------------------------------------------------*/
+int sci_updatebrowsevar(char *fname,unsigned long fname_len)
+{
+ CheckRhs(0, 0);
+ CheckLhs(0, 1);
+
+ UpdateBrowseVar(TRUE);
+
+ LhsVar(1) = 0;
+ PutLhsVar();
+ return 0;
+}
+/*--------------------------------------------------------------------------*/
<PRIMITIVE gatewayId="67" primitiveId="1" primitiveName="editvar" />
<PRIMITIVE gatewayId="67" primitiveId="2" primitiveName="browsevar" />
<PRIMITIVE gatewayId="67" primitiveId="3" primitiveName="filebrowser" />
+<PRIMITIVE gatewayId="67" primitiveId="4" primitiveName="updatebrowsevar" />
</GATEWAY>
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+#include "ui_data.h"
+#include "api_scilab.h"
+#include "Scierror.h"
+
+void putScilabVariable(char * name, char ** lines, int rows, int cols)
+{
+ SciErr sciErr;
+
+ if (rows != 0 && cols != 0)
+ {
+ sciErr = createNamedMatrixOfString(pvApiCtx, name, rows, cols, lines);
+ }
+ else
+ {
+ sciErr = createNamedMatrixOfDouble(pvApiCtx, name, 0, 0, NULL);
+ }
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ }
+}
+
+char * getUnnamedVariable()
+{
+ char buffer[128];
+ int i = 0;
+
+ do
+ {
+ sprintf(buffer, "%s%i", "unnamed", i++);
+ }
+ while (isNamedVarExist(pvApiCtx, buffer));
+
+ return strdup(buffer);
+}
public static final String DOUBLE = "Double";
/**
+ * Boolean sparse type
+ */
+ public static final String BOOLEANSPARSE = "Boolean Sparse";
+
+ /**
+ * Sparse type
+ */
+ public static final String SPARSE = "Sparse";
+
+ /**
+ * Complex sparse type
+ */
+ public static final String COMPLEXSPARSE = "Complex Sparse";
+
+ /**
* Complex type
*/
public static final String COMPLEX = "Complex";
* @param variableName : name of the variable being edited.
*/
public static void openVariableEditorDouble(double[][] data, String variableName) {
- int rows = data.length;
- int cols = 0;
- if (rows != 0) { // Not an empty matrix
- cols = data[0].length;
+ int c = data.length == 0 ? 0 : data[0].length;
+ Double[][] dataDouble = new Double[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataDouble[i][j] = data[i][j];
+ }
}
+ VariableEditor editvar = ScilabVariableEditor.getVariableEditor(DOUBLE, dataDouble, variableName);
+ }
- // we need to transpose the matrix as the way to store elements is different in scilab
- // otherwise
- // 1 2 3 would be rendered 1 4 2 (for example)
- // 4 5 6 5 3 6
- Double[][] dataDouble = new Double[rows][cols];
- int k = 0;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- dataDouble[k % rows][k / rows] = data[i][j];
- k++;
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void openVariableEditorBooleanSparse(int[][] data, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Boolean[][] dataBool = new Boolean[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataBool[i][j] = data[i][j] == 1;
}
}
+ VariableEditor editvar = ScilabVariableEditor.getVariableEditor(BOOLEANSPARSE, dataBool, variableName);
+ }
- VariableEditor editvar = ScilabVariableEditor.getVariableEditor(DOUBLE, dataDouble, variableName);
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void openVariableEditorSparse(double[][] data, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Double[][] dataDouble = new Double[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataDouble[i][j] = data[i][j];
+ }
+ }
+ VariableEditor editvar = ScilabVariableEditor.getVariableEditor(SPARSE, dataDouble, variableName);
}
/**
* @param data : scilab double matrix
* @param variableName : name of the variable being edited.
*/
- public static void openVariableEditorInteger8(byte[][] data, String variableName) {
- int rows = data.length;
- int cols = data[0].length;
- Byte[][] dataInteger = new Byte[rows][cols];
- int k = 0;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- dataInteger[k % rows][k / rows] = data[i][j];
- k++;
+ public static void openVariableEditorComplexSparse(double[][] realData, double[][] complexData, String variableName) {
+ int c = realData.length == 0 ? 0 : realData[0].length;
+ Double[][][] dataDoubleComplex = new Double[realData.length][c][2];
+ for (int i = 0; i < realData.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataDoubleComplex[i][j][0] = realData[i][j];
+ dataDoubleComplex[i][j][1] = complexData[i][j];
}
}
+ VariableEditor editvar = ScilabVariableEditor.getVariableEditor(COMPLEXSPARSE, dataDoubleComplex, variableName);
+ }
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void openVariableEditorInteger8(byte[][] data, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Byte[][] dataInteger = new Byte[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
+ }
+ }
VariableEditor editvar = ScilabVariableEditor.getVariableEditor(INTEGER, dataInteger, variableName);
}
* @param variableName : name of the variable being edited.
*/
public static void openVariableEditorUInteger8(short[][] data, String variableName) {
- int rows = data.length;
- int cols = data[0].length;
- Short[][] dataInteger = new Short[rows][cols];
- int k = 0;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- dataInteger[k % rows][k / rows] = data[i][j];
- k++;
+ int c = data.length == 0 ? 0 : data[0].length;
+ Short[][] dataInteger = new Short[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
}
}
-
VariableEditor editvar = ScilabVariableEditor.getVariableEditor(INTEGER, dataInteger, variableName);
}
* @param variableName : name of the variable being edited.
*/
public static void openVariableEditorInteger16(short[][] data, String variableName) {
- int rows = data.length;
- int cols = data[0].length;
- Short[][] dataInteger = new Short[rows][cols];
- int k = 0;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- dataInteger[k % rows][k / rows] = data[i][j];
- k++;
+ int c = data.length == 0 ? 0 : data[0].length;
+ Short[][] dataInteger = new Short[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
}
}
-
VariableEditor editvar = ScilabVariableEditor.getVariableEditor(INTEGER, dataInteger, variableName);
}
* @param variableName : name of the variable being edited.
*/
public static void openVariableEditorUInteger16(int[][] data, String variableName) {
- int rows = data.length;
- int cols = data[0].length;
- Integer[][] dataInteger = new Integer[rows][cols];
- int k = 0;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- dataInteger[k % rows][k / rows] = data[i][j];
- k++;
+ int c = data.length == 0 ? 0 : data[0].length;
+ Integer[][] dataInteger = new Integer[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
}
}
-
VariableEditor editvar = ScilabVariableEditor.getVariableEditor(INTEGER, dataInteger, variableName);
}
* @param variableName : name of the variable being edited.
*/
public static void openVariableEditorInteger32(int[][] data, String variableName) {
- int rows = data.length;
- int cols = data[0].length;
- Integer[][] dataInteger = new Integer[rows][cols];
- int k = 0;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- dataInteger[k % rows][k / rows] = data[i][j];
- k++;
+ int c = data.length == 0 ? 0 : data[0].length;
+ Integer[][] dataInteger = new Integer[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
}
}
-
VariableEditor editvar = ScilabVariableEditor.getVariableEditor(INTEGER, dataInteger, variableName);
}
* @param variableName : name of the variable being edited.
*/
public static void openVariableEditorUInteger32(long[][] data, String variableName) {
- int rows = data.length;
- int cols = data[0].length;
- Long[][] dataInteger = new Long[rows][cols];
- int k = 0;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- dataInteger[k % rows][k / rows] = data[i][j];
- k++;
+ int c = data.length == 0 ? 0 : data[0].length;
+ Long[][] dataInteger = new Long[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
}
}
-
VariableEditor editvar = ScilabVariableEditor.getVariableEditor(INTEGER, dataInteger, variableName);
}
* @param variableName : name of the variable being edited.
*/
public static void openVariableEditorString(String[][] data, String variableName) {
- int rows = data.length;
- int cols = data[0].length;
- String[][] dataString = new String[rows][cols];
- int k = 0;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- dataString[k % rows][k / rows] = data[i][j];
- k++;
+ VariableEditor editvar = ScilabVariableEditor.getVariableEditor(STRING, data, variableName);
+ }
+
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param realData : real part of scilab double matrix
+ * @param complexData : complex part of scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void openVariableEditorComplex(double[][] realData, double[][] complexData, String variableName) {
+ int c = realData.length == 0 ? 0 : realData[0].length;
+ Double[][][] dataDoubleComplex = new Double[realData.length][c][2];
+ for (int i = 0; i < realData.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataDoubleComplex[i][j][0] = realData[i][j];
+ dataDoubleComplex[i][j][1] = complexData[i][j];
+ }
+ }
+ VariableEditor editvar = ScilabVariableEditor.getVariableEditor(COMPLEX, dataDoubleComplex, variableName);
+ }
+
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void openVariableEditorBoolean(int[][] data, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Boolean[][] dataBool = new Boolean[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataBool[i][j] = data[i][j] == 1;
}
}
+ VariableEditor editvar = ScilabVariableEditor.getVariableEditor(BOOLEAN, dataBool, variableName);
+ }
+
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorDouble(double[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Double[][] dataDouble = new Double[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataDouble[i][j] = data[i][j];
+ }
+ }
+ ScilabVariableEditor.refreshVariableEditor(DOUBLE, dataDouble, rowsIndex, colsIndex, variableName);
+ }
- VariableEditor editvar = ScilabVariableEditor.getVariableEditor(STRING, dataString, variableName);
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorBooleanSparse(int[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Boolean[][] dataBool = new Boolean[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataBool[i][j] = data[i][j] == 1;
+ }
+ }
+ ScilabVariableEditor.refreshVariableEditor(BOOLEANSPARSE, dataBool, rowsIndex, colsIndex, variableName);
+ }
+
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorSparse(double[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Double[][] dataDouble = new Double[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataDouble[i][j] = data[i][j];
+ }
+ }
+ ScilabVariableEditor.refreshVariableEditor(SPARSE, dataDouble, rowsIndex, colsIndex, variableName);
}
/**
* @param complexData : complex part of scilab double matrix
* @param variableName : name of the variable being edited.
*/
- public static void openVariableEditorComplex(double[][] realData, double[][] complexData, String variableName) {
- int rows = realData.length;
- int cols = realData[0].length;
- Double[][][] dataDoubleComplex = new Double[rows][cols][2];
- int k = 0;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- dataDoubleComplex[k % rows][k / rows][0] = realData[i][j];
- dataDoubleComplex[k % rows][k / rows][1] = complexData[i][j];
- k++;
+ public static void refreshVariableEditorComplexSparse(double[][] realData, double[][] complexData, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = realData.length == 0 ? 0 : realData[0].length;
+ Double[][][] dataDoubleComplex = new Double[realData.length][c][2];
+ for (int i = 0; i < realData.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataDoubleComplex[i][j][0] = realData[i][j];
+ dataDoubleComplex[i][j][1] = complexData[i][j];
}
}
+ ScilabVariableEditor.refreshVariableEditor(COMPLEXSPARSE, dataDoubleComplex, rowsIndex, colsIndex, variableName);
+ }
- VariableEditor editvar = ScilabVariableEditor.getVariableEditor(COMPLEX, dataDoubleComplex, variableName);
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorInteger8(byte[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Byte[][] dataInteger = new Byte[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
+ }
+ }
+ ScilabVariableEditor.refreshVariableEditor(INTEGER, dataInteger, rowsIndex, colsIndex, variableName);
}
/**
* @param data : scilab double matrix
* @param variableName : name of the variable being edited.
*/
- public static void openVariableEditorBoolean(int[][] data, String variableName) {
- int rows = data.length;
- int cols = data[0].length;
- Boolean[][] dataBool = new Boolean[rows][cols];
- int k = 0;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- dataBool[k % rows][k / rows] = data[i][j] == 1;
- k++;
+ public static void refreshVariableEditorUInteger8(short[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Short[][] dataInteger = new Short[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
}
}
+ ScilabVariableEditor.refreshVariableEditor(INTEGER, dataInteger, rowsIndex, colsIndex, variableName);
+ }
- VariableEditor editvar = ScilabVariableEditor.getVariableEditor(BOOLEAN, dataBool, variableName);
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorInteger16(short[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Short[][] dataInteger = new Short[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
+ }
+ }
+ ScilabVariableEditor.refreshVariableEditor(INTEGER, dataInteger, rowsIndex, colsIndex, variableName);
+ }
+
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorUInteger16(int[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Integer[][] dataInteger = new Integer[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
+ }
+ }
+ ScilabVariableEditor.refreshVariableEditor(INTEGER, dataInteger, rowsIndex, colsIndex, variableName);
+ }
+
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorInteger32(int[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Integer[][] dataInteger = new Integer[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
+ }
+ }
+ ScilabVariableEditor.refreshVariableEditor(INTEGER, dataInteger, rowsIndex, colsIndex, variableName);
+ }
+
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorUInteger32(long[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Long[][] dataInteger = new Long[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataInteger[i][j] = data[i][j];
+ }
+ }
+ ScilabVariableEditor.refreshVariableEditor(INTEGER, dataInteger, rowsIndex, colsIndex, variableName);
+ }
+
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorString(String[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ ScilabVariableEditor.refreshVariableEditor(STRING, data, rowsIndex, colsIndex, variableName);
+ }
+
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param realData : real part of scilab double matrix
+ * @param complexData : complex part of scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorComplex(double[][] realData, double[][] complexData, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = realData.length == 0 ? 0 : realData[0].length;
+ Double[][][] dataDoubleComplex = new Double[realData.length][c][2];
+ for (int i = 0; i < realData.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataDoubleComplex[i][j][0] = realData[i][j];
+ dataDoubleComplex[i][j][1] = complexData[i][j];
+ }
+ }
+ ScilabVariableEditor.refreshVariableEditor(COMPLEX, dataDoubleComplex, rowsIndex, colsIndex, variableName);
+ }
+
+ /**
+ * Open variable Editor with information given by Scilab
+ * @param data : scilab double matrix
+ * @param variableName : name of the variable being edited.
+ */
+ public static void refreshVariableEditorBoolean(int[][] data, double[] rowsIndex, double[] colsIndex, String variableName) {
+ int c = data.length == 0 ? 0 : data[0].length;
+ Boolean[][] dataBool = new Boolean[data.length][c];
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < c; j++) {
+ dataBool[i][j] = data[i][j] == 1;
+ }
+ }
+ ScilabVariableEditor.refreshVariableEditor(BOOLEAN, dataBool, rowsIndex, colsIndex, variableName);
}
/**
--- /dev/null
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.4
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.scilab.modules.ui_data;
+
+
+ /**
+ * ui_data management
+ * @author Vincent COUVERT
+ * @author Allan CORNET
+ * @copyright INRIA
+ */
+public class UI_data {
+
+ /**
+ * Constructor
+ */
+ protected UI_data() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Put a scilab variable as an array of strings in C envrionment
+ * @param lines array of string
+ * @param rows the number of rows
+ * @param cols the number of cols
+ */
+public static void putScilabVariable(String name, String[] lines, int rows, int cols) {
+ UI_dataJNI.putScilabVariable(name, lines, rows, cols);
+ }
+
+
+ /**
+ * Put a scilab variable as an array of strings in C envrionment
+ * @param lines array of string
+ * @param rows the number of rows
+ * @param cols the number of cols
+ */
+public static String getUnnamedVariable() {
+ return UI_dataJNI.getUnnamedVariable();
+ }
+
+}
--- /dev/null
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 2.0.4
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.scilab.modules.ui_data;
+
+
+/* It is generated code. Disable checkstyle */
+//CHECKSTYLE:OFF
+ /**
+ * All Scilab history management used in Java console
+ * @author Vincent COUVERT
+ * @author Allan CORNET
+ * @copyright INRIA
+ */
+class UI_dataJNI {
+
+ /**
+ * Constructor
+ */
+ protected UI_dataJNI() {
+ throw new UnsupportedOperationException();
+ }
+
+ static {
+ try {
+ System.loadLibrary("sciui_data");
+ } catch (SecurityException e) {
+ System.err.println("A security manager exists and does not allow the loading of the specified dynamic library.");
+ System.err.println(e.getLocalizedMessage());
+ e.printStackTrace(System.err);
+ } catch (UnsatisfiedLinkError e) {
+ System.err.println("The native library sciui_data does not exist or cannot be found.");
+ System.err.println(e.getLocalizedMessage());
+ e.printStackTrace(System.err);
+ }
+ }
+
+ public final static native void putScilabVariable(String jarg1, String[] jarg2, int jarg3, int jarg4);
+ public final static native String getUnnamedVariable();
+}
package org.scilab.modules.ui_data.datatable;
+import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.util.Arrays;
+import java.util.Vector;
import javax.swing.JTable;
+import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement;
import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
import org.scilab.modules.gui.events.callback.CallBack;
import org.scilab.modules.ui_data.EditVar;
+import org.scilab.modules.ui_data.UI_data;
import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
import org.scilab.modules.ui_data.variableeditor.celleditor.ScilabGenericCellEditor;
import org.scilab.modules.ui_data.variableeditor.undo.CellsUndoManager;
private static final String COMMA = ",";
private static final String SEMI = ";";
- private static final ActionListener EMPTYACTION = new ActionListener() {
- public void actionPerformed(ActionEvent e) { }
- };
-
private int scilabMatrixRowCount;
private int scilabMatrixColCount;
private int currentRow = -1;
private SwingScilabVariableEditor editor;
private CellsUndoManager undoManager;
+ private Vector copyVector;
+
/**
* Default construction setting table data.
* @param editor the editor
* @param data : the data to store.
* @param cellEditor the cellEditor
*/
- public SwingEditvarTableModel(SwingScilabVariableEditor editor, String varName, String type, Object[][] data, ScilabGenericCellEditor cellEditor) {
+ public SwingEditvarTableModel(SwingScilabVariableEditor editor, String varName, String type, Object[][] data, ScilabGenericCellEditor cellEditor, int rows, int cols) {
this.editor = editor;
this.varName = varName;
scilabMatrixRowCount = data.length;
scilabMatrixColCount = data[0].length;
}
this.type = type;
- this.setDataVector(data);
+ this.setDataVector(data, rows, cols);
+ this.cellEditor = cellEditor;
+ this.undoManager = new CellsUndoManager(editor);
+ }
+
+ /**
+ * Change the data
+ * @param type the data type
+ * @param data the datas
+ * @param cellEditor the cell editor
+ * @param rows the number of rows
+ * @param cols the number of columns
+ */
+ public void changeData(String type, Object[][] data, ScilabGenericCellEditor cellEditor, int rows, int cols) {
+ this.type = type;
this.cellEditor = cellEditor;
- this.undoManager = new CellsUndoManager(editor, getCommandFromMatrix());
- expandTable();
+ scilabMatrixRowCount = data.length;
+ scilabMatrixColCount = 0;
+ if (scilabMatrixRowCount != 0) { // Not an empty matrix
+ scilabMatrixColCount = data[0].length;
+ }
+ setDataVector(data, rows, cols);
+ }
+
+ /**
+ * Change all the data
+ * @param v the data vector
+ * @param row the number of rows
+ * @param row the number of columns
+ */
+ public void changeData(Vector v, int row, int col) {
+ dataVector = v;
+ scilabMatrixRowCount = row;
+ scilabMatrixColCount = col;
+ updateFullMatrix(null, 0, 0);
}
/**
* {@inheritDoc}
*/
- public void setDataVector(Object[][] data) {
- int cols = 0;
+ public void setDataVector(Object[][] data, int rows, int cols) {
+ int colsData = 0;
if (data.length != 0) { // Not an empty matrix
- cols = data[0].length;
+ colsData = data[0].length;
+ }
+
+ int c = Math.max(cols, colsData);
+
+ Vector identifiers = new Vector(c);
+ for (int i = 0; i < c; ++i) {
+ identifiers.addElement(i + 1);
+ }
+ super.setDataVector(convertData(data, rows, cols), identifiers);
+ }
+
+ /**
+ * Convert datas as arrays in a Vector object
+ * @param data the datas
+ * @param rows the number of rows
+ * @param columns the number of columns
+ * @return the corresponding Vector
+ */
+ protected Vector convertData(Object[][] data, int rows, int cols) {
+ int r = Math.max(data.length, rows);
+ int c = 0;
+ if (data.length != 0) {
+ c = Math.max(data[0].length, cols);
+ }
+ Vector rv = new Vector(r);
+ for (int i = 0; i < data.length; i++) {
+ Vector cv = new Vector(c);
+ for (int j = 0; j < data[i].length; j++) {
+ cv.addElement(data[i][j]);
+ }
+ for (int j = 0; j < cols - data[i].length; j++) {
+ cv.addElement(null);
+ }
+ rv.addElement(cv);
+ }
+ for (int i = 0; i < rows - data.length; i++) {
+ Vector cv = new Vector(c);
+ for (int j = 0; j < c; j++) {
+ cv.addElement(null);
+ }
+ rv.addElement(cv);
+ }
+
+ return rv;
+ }
+
+ /**
+ * Enlarge the model
+ * @param rows the number of rows
+ * @param columns the number of columns
+ * @return true if the model has been enlarged
+ */
+ public boolean enlarge(int rows, int cols) {
+ boolean isEnlarged = false;
+
+ if (cols > getColumnCount()) {
+ addColumns(cols - getColumnCount());
+ isEnlarged = true;
}
- Integer[] identifiers = new Integer[cols];
- for (int i = 0; i < cols; ++i) {
- identifiers[i] = i + 1;
+ if (rows > getRowCount()) {
+ int r = rows - getRowCount();
+ for (int i = 0; i < r; i++) {
+ Vector v = new Vector(getColumnCount());
+ for (int j = 0; j < getColumnCount(); j++) {
+ v.addElement(null);
+ }
+ dataVector.addElement(v);
+ }
+ isEnlarged = true;
}
- super.setDataVector(data, identifiers);
+ return isEnlarged;
+ }
+
+ /**
+ * Clone the datas
+ * @return the cloned datas
+ */
+ public Vector cloneDatas() {
+ Vector v = new Vector(dataVector.size());
+ for (int i = 0; i < dataVector.size(); i++) {
+ Vector vv = (Vector) dataVector.get(i);
+ if (vv != null) {
+ v.addElement(vv.clone());
+ } else {
+ v.addElement(null);
+ }
+ }
+ return v;
+ }
+
+ /**
+ * Add columns to the model
+ * @param number the number of columns to add
+ */
+ public void addColumns(int number) {
+ columnIdentifiers.setSize(getColumnCount() + number);
+ for (int i = 0; i < getRowCount(); i++) {
+ ((Vector) dataVector.elementAt(i)).setSize(getColumnCount());
+ }
+ }
+
+ /**
+ * Add rows
+ * @param number the number of rows to add
+ */
+ public void addRows(int number) {
+ enlarge(getRowCount() + number, getColumnCount());
}
/**
}
/**
- * @return the tyype of this tableModel
+ * @return the type of this tableModel
*/
public String getType() {
return type;
}
/**
+ * @return the type of this tableModel
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @return the Scilab matrix rows number
+ */
+ public int getScilabMatrixRowCount() {
+ return scilabMatrixRowCount;
+ }
+
+ /**
+ * @return the Scilab matrix columns number
+ */
+ public int getScilabMatrixColCount() {
+ return scilabMatrixColCount;
+ }
+
+ /**
* @param row the row
* @param col the col
* @param useDefault if true, null is replaced by the default value
}
if (type.equals(EditVar.STRING)) {
- str = GUILL + str + GUILL;
+ str = GUILL + getDataAsScilabString(str) + GUILL;
}
return str;
* @param row the row
* @param col the col
*/
- public void setValueAtAndUpdate(boolean mustUpdate, Object value, int row, int col) {
+ public void setValueAtAndUpdate(boolean mustUpdate, boolean addUndoableEdit, Object value, int row, int col) {
+ Object oldValue = addUndoableEdit ? getValueAt(row, col) : null;
+ int oldScilabMatrixRowCount = scilabMatrixRowCount;
+ int oldScilabMatrixColCount = scilabMatrixColCount;
+
+ copyVector = null;
+ boolean defaultAdded = setValue(value, row, col);
+
+ if (defaultAdded) {
+ fireTableChanged(new TableModelEvent(this));
+ } else {
+ fireTableCellUpdated(row, col);
+ }
+
+ if (mustUpdate) {
+ if (defaultAdded) {
+ updateFullMatrix(copyVector, oldScilabMatrixRowCount, oldScilabMatrixColCount);
+ } else {
+ updateMatrix(oldValue, row, col);
+ }
+ }
+ }
+
+ /**
+ * Set a value at the given row and column
+ * @param value the value to set
+ * @param row the row
+ * @param col the column
+ * @return true if the matrix has been enlarged (typically when the value to set is outside the actual matrix, zeros are added)
+ */
+ public boolean setValue(Object value, int row, int col) {
if (value == null || (value instanceof String && ((String) value).length() == 0)) {
- return;
+ return false;
}
+ Object defaultValue = getDefaultValue();
boolean defaultAdded = false;
- for (int i = scilabMatrixRowCount; i <= Math.max(row, scilabMatrixRowCount - 1); i++) {
- for (int j = 0; j <= Math.max(col, scilabMatrixColCount - 1); j++) {
- super.setValueAt(getDefaultValue(), i, j);
- if (!defaultAdded) {
- defaultAdded = true;
+
+ if (row >= scilabMatrixRowCount) {
+ for (int i = scilabMatrixRowCount; i <= row; i++) {
+ Vector rowVector = (Vector) dataVector.elementAt(i);
+ for (int j = 0; j <= Math.max(col, scilabMatrixColCount - 1); j++) {
+ rowVector.setElementAt(defaultValue, j);
+ if (copyVector == null) {
+ copyVector = (Vector) dataVector.clone();
+ }
+ if (!defaultAdded) {
+ defaultAdded = true;
+ }
}
}
}
- for (int i = scilabMatrixColCount; i <= Math.max(col, scilabMatrixColCount - 1); i++) {
- for (int j = 0; j <= Math.max(row, scilabMatrixRowCount - 1); j++) {
- super.setValueAt(getDefaultValue(), j, i);
- if (!defaultAdded) {
- defaultAdded = true;
+ if (col >= scilabMatrixColCount) {
+ for (int i = 0; i <= Math.max(row, scilabMatrixRowCount - 1); i++) {
+ Vector rowVector = (Vector) dataVector.elementAt(i);
+ for (int j = scilabMatrixColCount; j <= col; j++) {
+ rowVector.setElementAt(defaultValue, j);
+ if (copyVector == null) {
+ copyVector = (Vector) dataVector.clone();
+ }
+ if (!defaultAdded) {
+ defaultAdded = true;
+ }
}
}
}
- String exp = value.toString();
-
- if (exp.startsWith(EQUAL) && !exp.matches("=[ ]*")) {
- exp = exp.substring(1);
- super.setValueAt(exp, row, col);
- // keep the expression
- if (exp.length() > 0) {
- cellEditor.addExpression(exp, row, col);
- }
- } else {
- cellEditor.removeExpression(row, col);
- super.setValueAt(value, row, col);
- }
+ ((Vector) dataVector.elementAt(row)).setElementAt(value, col);
if (col >= scilabMatrixColCount || row >= scilabMatrixRowCount) {
if (col >= scilabMatrixColCount) {
if (row >= scilabMatrixRowCount) {
scilabMatrixRowCount = row + 1;
}
- expandTable();
}
- if (mustUpdate) {
- if (defaultAdded) {
- updateMatrix();
- } else {
- updateMatrix(exp, row, col);
+ return defaultAdded;
+ }
+
+ /**
+ * Set values at the given row and column
+ * @param data the datas
+ * @param row the row index
+ * @param col the column index
+ * @return true if the matrix has been enlarged
+ */
+ public boolean setValues(Vector data, int row, int col) {
+ int countCols = 0;
+ for (int i = 0; i < data.size(); i++) {
+ countCols = Math.max(countCols, ((Vector) data.get(i)).size());
+ }
+ boolean isModified = enlarge(row + data.size(), col + countCols);
+
+ for (int i = 0; i < data.size(); i++) {
+ for (int j = 0; j < ((Vector) data.get(i)).size(); j++) {
+ isModified = setValue(((Vector) data.get(i)).get(j), row + i, col + j) || isModified;
}
}
+
+ return isModified;
}
/**
* {@inheritDoc}
*/
public void setValueAt(Object value, int row, int col) {
- setValueAtAndUpdate(true, value, row, col);
+ setValueAtAndUpdate(true, true, value, row, col);
currentRow = row;
currentCol = col;
}
public void removeRow(int row, int colB, int colE) {
if (row == scilabMatrixRowCount - 1 && colB == 0 && colE >= scilabMatrixColCount - 1) {
scilabMatrixRowCount--;
- removeRow(row);
+ Vector v = (Vector) dataVector.get(row);
+ for (int i = 0; i < scilabMatrixColCount; i++) {
+ v.setElementAt(null, i);
+ }
}
}
* @param rowB the first row
* @param rowE the last row
*/
- public void removeCol(JTable table, int col, int rowB, int rowE) {
+ public void removeCol(int col, int rowB, int rowE) {
if (col == scilabMatrixColCount - 1 && rowB == 0 && rowE >= scilabMatrixRowCount - 1) {
scilabMatrixColCount--;
- table.removeColumn(table.getColumnModel().getColumn(col));
+ for (int i = 0; i < scilabMatrixRowCount; i++) {
+ ((Vector) dataVector.get(i)).setElementAt(null, col);
+ }
}
}
/**
- * Update all the matrix on the Scilab's side.
+ * @param cols the column indexes to remove, the array is supposed to be ordered
*/
- public void updateMatrix() {
- execCommand(getCommandFromMatrix());
+ public void removeColumns(int[] cols) {
+ Vector copy = null;
+ int oldRowCount = scilabMatrixRowCount;
+ int oldColCount = scilabMatrixColCount;
+ int c = 0;
+ for (Integer col : cols) {
+ if (col - c < scilabMatrixColCount) {
+ if (copy == null) {
+ copy = cloneDatas();
+ }
+ if (col - c == scilabMatrixColCount - 1) {
+ for (int i = 0; i < scilabMatrixRowCount; i++) {
+ ((Vector) dataVector.get(i)).setElementAt(null, col - c);
+ }
+ } else {
+ for (int i = 0; i < scilabMatrixRowCount; i++) {
+ ((Vector) dataVector.get(i)).removeElementAt(col - c);
+ }
+ }
+ scilabMatrixColCount--;
+ c++;
+ }
+ }
+ if (copy != null) {
+ fireTableStructureChanged();
+ updateFullMatrix(copy, oldRowCount, oldColCount);
+ }
}
/**
- * Expand the table
+ * @param rows the row indexes to remove, the array is supposed to be ordered
*/
- public void expandTable() {
- int newTableColCount = 42;
- int newTableRowCount = 42;
- // row
- if (getColumnCount() > 32) {
- newTableColCount = scilabMatrixColCount + 10;
+ public void removeRows(int[] rows) {
+ Vector copy = null;
+ int oldRowCount = scilabMatrixRowCount;
+ int oldColCount = scilabMatrixColCount;
+ int r = 0;
+ for (Integer row : rows) {
+ if (row - r < scilabMatrixRowCount) {
+ if (copy == null) {
+ copy = cloneDatas();
+ }
+ if (row - r == scilabMatrixRowCount - 1) {
+ Vector rv = (Vector) dataVector.get(row - r);
+ for (int i = 0; i < scilabMatrixColCount; i++) {
+ rv.setElementAt(null, i);
+ }
+ } else {
+ dataVector.removeElementAt(row - r);
+ }
+ scilabMatrixRowCount--;
+ fireTableRowsDeleted(row - r, row - r);
+ r++;
+ }
}
- for (int i = getColumnCount(); i < newTableColCount; i++) {
- addColumn(i + 1);
+ if (copy != null) {
+ updateFullMatrix(copy, oldRowCount, oldColCount);
}
- // col
- if (getRowCount() > 32) {
- newTableRowCount = scilabMatrixRowCount + 10;
+ }
+
+ /**
+ * @param col the column index to insert
+ */
+ public void insertColumn(int col) {
+ if (col < scilabMatrixColCount - 1) {
+ Vector copy = cloneDatas();
+ int oldRowCount = scilabMatrixRowCount;
+ int oldColCount = scilabMatrixColCount;
+ Object o = getDefaultValue();
+ for (int i = 0; i < scilabMatrixRowCount; i++) {
+ ((Vector) dataVector.get(i)).insertElementAt(o, col);
+ }
+ scilabMatrixColCount++;
+ updateFullMatrix(copy, oldRowCount, oldColCount);
}
- for (Integer i = getRowCount(); i < newTableRowCount; i++) {
- Object[] newRow = new Object[newTableColCount];
- addRow(newRow);
+ }
+
+ /**
+ * @param row the row index to insert
+ */
+ public void insertRow(int row) {
+ if (row < scilabMatrixRowCount - 1) {
+ Vector copy = cloneDatas();
+ int oldRowCount = scilabMatrixRowCount;
+ int oldColCount = scilabMatrixColCount;
+ Object o = getDefaultValue();
+ Vector v = new Vector(getColumnCount());
+ for (int i = 0; i < scilabMatrixColCount; i++) {
+ v.addElement(o);
+ }
+ for (int i = scilabMatrixColCount; i < getColumnCount(); i++) {
+ v.addElement(null);
+ }
+ dataVector.insertElementAt(v, row);
+ scilabMatrixRowCount++;
+ updateFullMatrix(copy, oldRowCount, oldColCount);
}
}
/**
- * Refresh the current matrix
+ * Update all the matrix on the Scilab's side.
*/
- public void refreshMatrix() {
- execCommand("editvar(\"" + varName + "\");");
+ public void updateFullMatrix(Object oldValue, int oldRow, int oldCol) {
+ String[] mat = getSubMatrix(0, scilabMatrixRowCount - 1, 0, scilabMatrixColCount - 1);
+ UI_data.putScilabVariable("L?8625083632641564278", mat, scilabMatrixRowCount, scilabMatrixColCount);
+ String command;
+ if (type.equals(EditVar.SPARSE) || type.equals(EditVar.COMPLEXSPARSE) || type.equals(EditVar.BOOLEANSPARSE)) {
+ command = buildScilabRequest(varName + "=sparse(evstr(L?8625083632641564278))", "editvar(\"" + varName + "\"),clear(\"L?8625083632641564278\")");
+ } else {
+ command = buildScilabRequest(varName + "=evstr(L?8625083632641564278)", "editvar(\"" + varName + "\"),clear(\"L?8625083632641564278\")");
+ }
+ execCommand(command, oldValue, oldRow, oldCol);
}
/**
- * @param command the command to execute.
+ * Get a submatrix
+ * @param rowB first row index
+ * @param rowE last row index
+ * @param colB first col index
+ * @param colE last col index
+ * @return the corresponding submatrix
*/
- public void updateCommand(String command) {
- try {
- ScilabInterpreterManagement.asynchronousScilabExec(EMPTYACTION, command);
- } catch (InterpreterException e1) {
- System.err.println(e1);
+ private String[] getSubMatrix(int rowB, int rowE, int colB, int colE) {
+ int row = rowE - rowB + 1;
+ int col = colE - colB + 1;
+ String[] mat = new String[row * col];
+ for (int i = 0; i < row; i++) {
+ for (int j = 0; j < col; j++) {
+ mat[j * row + i] = getScilabValueAt(i + rowB, j + colB);
+ }
}
+
+ return mat;
}
/**
- * Update all the matrix on the Scilab's side.
- * @return the command to create the matrix
+ * Get a Scilab submatrix
+ * @param varName the variable name
+ * @param rowB first row index
+ * @param rowE last row index
+ * @param colB first col index
+ * @param colE last col index
+ */
+ public String getScilabSubMatrix(int[] rows, int[] cols, int[] rowSize, int[] colSize) {
+ if (rows.length == 0 || cols.length == 0) {
+ return null;
+ }
+
+ int rowC = getScilabMatrixRowCount() - 1;
+ int colC = getScilabMatrixColCount() - 1;
+ String rowsLim = getLimits(rows, rowC, rowSize);
+ if (rowsLim == null) {
+ return null;
+ }
+
+ String colsLim = getLimits(cols, colC, colSize);
+ if (colsLim == null) {
+ return null;
+ }
+
+ if (rowSize[0] == rowC + 1 && colSize[0] == colC + 1) {
+ return getVarName();
+ } else {
+ return getVarName() + "(" + rowsLim + "," + colsLim + ")";
+ }
+ }
+
+ public String getScilabSubMatrix(int[] rows, int[] cols) {
+ int[] csize = new int[1];
+ int[] rsize = new int[1];
+
+ return getScilabSubMatrix(rows, cols, csize, rsize);
+ }
+
+ /**
+ * Build the Scilab indexes to extract the corresponding matrix.
+ * For example, if index={1,2,3,5,6,10} then the string "1:3,5:6,10" will be returned.
+ * @param index the indexes
+ * @param max the maximum value that an index can have
+ * @param size an array of length 1 which will contain the total size (e.g. with the previous example size[0] will be 6)
+ * @return the corresponding Scilab string
*/
- public String getCommandFromMatrix() {
- String matrix = getDataAsScilabString(getMatrix());
- String expr = varName + EQUAL + matrix;
- return buildScilabRequest(expr);
+ private static String getLimits(int[] index, int max, int[] size) {
+ if (index.length == 0 || index[0] > max) {
+ return null;
+ }
+
+ Vector<Integer> lim = new Vector<Integer>(2 * index.length);
+ int i = 1;
+
+ lim.addElement(index[0]);
+ for (; i < index.length && index[i] <= max; i++) {
+ if (index[i] != index[i - 1] + 1) {
+ lim.addElement(index[i - 1]);
+ lim.addElement(index[i]);
+ }
+ }
+
+ if (i == index.length) {
+ lim.addElement(index[index.length - 1]);
+ } else {
+ lim.addElement(max);
+ }
+
+ if (lim.size() == 2) {
+ size[0] = lim.get(1) - lim.get(0) + 1;
+ if (lim.get(0) == 0 && lim.get(1) == max) {
+ return ":";
+ } else {
+ if (lim.get(0) == lim.get(1)) {
+ return Integer.toString(lim.get(0) + 1);
+ } else {
+ return (lim.get(0) + 1) + ":" + (lim.get(1) + 1);
+ }
+ }
+ }
+
+ StringBuilder buf = new StringBuilder("[");
+ size[0] = 0;
+ for (i = 0; i < lim.size(); i += 2) {
+ size[0] += lim.get(i + 1) - lim.get(i) + 1;
+ buf.append(lim.get(i) + 1);
+ if (lim.get(i) != lim.get(i + 1)) {
+ buf.append(":");
+ buf.append(lim.get(i + 1) + 1);
+ }
+ if (i == lim.size() - 2) {
+ buf.append("]");
+ } else {
+ buf.append(",");
+ }
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * Refresh the current matrix
+ */
+ public void refreshMatrix() {
+ execCommand("editvar(\"" + varName + "\");");
}
/**
*/
private Object getDefaultValue() {
Object ret = null;
- if (type.equals(EditVar.STRING)) {
- ret = "";
- } else if (type.equals(EditVar.DOUBLE)) {
+ if (type.equals(EditVar.DOUBLE)) {
ret = new Double(0.0);
+ } else if (type.equals(EditVar.STRING)) {
+ ret = "";
} else if (type.equals(EditVar.INTEGER)) {
ret = new Integer(0);
} else if (type.equals(EditVar.COMPLEX)) {
ret = new Double[]{0.0, 0.0};
} else if (type.equals(EditVar.BOOLEAN)) {
ret = Boolean.FALSE;
+ } else if (type.equals(EditVar.SPARSE) || type.equals(EditVar.COMPLEXSPARSE) || type.equals(EditVar.BOOLEANSPARSE)) {
+ ret = "";
}
return ret;
* @return the default representation according to the type
*/
private String getDefaultStringValue() {
- if (type.equals(EditVar.STRING)) {
- return "";
+ if (type.equals(EditVar.DOUBLE) || type.equals(EditVar.COMPLEX) || type.equals(EditVar.INTEGER) || type.equals(EditVar.SPARSE) || type.equals(EditVar.COMPLEXSPARSE)) {
+ return "0";
}
- if (type.equals(EditVar.DOUBLE) || type.equals(EditVar.COMPLEX) || type.equals(EditVar.INTEGER)) {
- return "0";
+ if (type.equals(EditVar.STRING)) {
+ return "";
}
- if (type.equals(EditVar.BOOLEAN)) {
+ if (type.equals(EditVar.BOOLEAN) || type.equals(EditVar.BOOLEANSPARSE)) {
return "%f";
}
}
/**
- * @param value the value to update on the Scilab's side
+ * @param oldValue the value to update on the Scilab's side
* @param row the row coord
* @param col the col coord
*/
- private void updateMatrix(Object value, int row, int col) {
+ public void updateMatrix(Object oldValue, int row, int col) {
String val = getScilabValueAt(row, col);
String coords = "";
if (scilabMatrixRowCount != 1 || scilabMatrixColCount != 1) {
coords = "(" + (row + 1) + COMMA + (col + 1) + ")";
}
String expr = varName + coords + EQUAL + getDataAsScilabString(val);
- String command = buildScilabRequest(expr);
- execCommand(command);
+ String update = "editvar(\"" + varName + "\"," + varName + "(" + (row + 1) + "," + (col + 1) + ")," + (row + 1) + "," + (col + 1) + ");";
+ String command = buildScilabRequest(expr, update);
+ execCommand(command, oldValue, row, col);
+ }
+
+ /**
+ * Execute a command
+ * @param com the command
+ */
+ public void execCommand(String com) {
+ execCommand(com, null, 0 , 0);
}
/**
* @param com the command to execute.
*/
- private void execCommand(final String com) {
+ private void execCommand(final String com, final Object oldValue, final int row, final int col) {
try {
CallBack callback = new CallBack("") {
public void callBack() {
- undoManager.addEdit(new CellsUndoableEdit(SwingEditvarTableModel.this));
+ editor.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ if (oldValue != null) {
+ Object newValue;
+ if (oldValue instanceof Vector) {
+ newValue = (Vector) dataVector.clone();
+ } else {
+ newValue = getValueAt(row, col);
+ }
+ if (!oldValue.equals(newValue)) {
+ undoManager.addEdit(new CellsUndoableEdit(SwingEditvarTableModel.this, newValue, oldValue, row, col));
+ }
+ }
}
};
-
+ editor.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
ScilabInterpreterManagement.asynchronousScilabExec(callback, com);
} catch (InterpreterException e1) {
System.err.println(e1);
* @param expr the expr to put in the request.
* @return the request
*/
- private String buildScilabRequest(String expr) {
+ public static String buildScilabRequest(String expr, String update) {
StringBuilder command = new StringBuilder();
- command.append("L8625083632641564277=warning(\"query\");warning(\"off\");");
- command.append("if execstr(\"" + expr + SEMI + cellEditor.getAllExpressions(varName) + "\", \"errcatch\") <> 0 then ");
- command.append("messagebox(\"Could not edit variable: \" + lasterror() + \"\"");
- command.append(",\"Variable editor\", \"error\", \"modal\");");
+ command.append("L$8625083632641564277=warning(\"query\");warning(\"off\");");
+ command.append("if execstr(\"");
+ command.append(expr);
+ command.append("\",\"errcatch\") <> 0 then messagebox(\"Could not edit variable: \" + lasterror() + \"\"");
+ command.append(",\"Variable editor\",\"error\",\"modal\");");
command.append("end;");
- command.append("warning(L8625083632641564277);clear(\"L8625083632641564277\");");
- command.append("editvar(\"" + varName + "\");");
+ command.append("warning(L$8625083632641564277);clear(\"L$8625083632641564277\");");
+ command.append(update);
+ command.append(";");
+ command.append("updatebrowsevar()");
return command.toString();
}
* @return the Scilab matrix for this JTable
*/
private String getMatrix() {
- String str = "[";
+ StringBuilder str = new StringBuilder("[");
for (int i = 0; i < scilabMatrixRowCount; i++) {
for (int j = 0; j < scilabMatrixColCount; j++) {
+ str.append(getScilabValueAt(i, j));
if (j < scilabMatrixColCount - 1) {
- str += getScilabValueAt(i, j) + COMMA;
+ str.append(COMMA);
} else if (i < scilabMatrixRowCount - 1) {
- str += getScilabValueAt(i, j) + SEMI;
- } else {
- str += getScilabValueAt(i, j);
+ str.append(SEMI);
}
}
}
+ str.append("]");
- str += "]";
+ return str.toString();
+ }
- return str;
+ /**
+ * Refresh the model
+ */
+ public void refresh() {
+ try {
+ ScilabInterpreterManagement.asynchronousScilabExec(null, "editvar(\"" + varName + "\")");
+ } catch (InterpreterException e1) {
+ System.err.println(e1);
+ }
}
/**
* @param str the string where replace " and '
* @return the well-formed string
*/
- private String getDataAsScilabString(String str) {
- String data = str.replace(GUILL, "\"\""); // Change " to "" because added in an execstr command
- data = data.replace("'", "''"); // Change ' to '' because added in an execstr command
-
- return data;
+ public static String getDataAsScilabString(String str) {
+ return str.replace(GUILL, "\"\"").replace("'", "''");
}
}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.rowheader;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.UIManager;
+import javax.swing.border.AbstractBorder;
+import javax.swing.table.JTableHeader;
+import javax.swing.table.TableCellRenderer;
+
+/**
+ * @author Calixte DENIZET
+ */
+public class HeaderRenderer extends JLabel implements TableCellRenderer {
+
+ private static final Insets INSETS = new Insets(1, 1, 1, 0);
+
+ private int index;
+ private JTable table;
+ private boolean rowModel;
+
+ private Font selectedFont;
+ private Font unselectedFont;
+ private Color selectedFgColor;
+ private Color unselectedFgColor;
+ private Color selectedBgColor;
+ private Color unselectedBgColor;
+
+ /**
+ * Constructor
+ */
+ public HeaderRenderer(JTable table, boolean rowModel) {
+ this.table = table;
+ this.rowModel = rowModel;
+ JTableHeader header = table.getTableHeader();
+ this.selectedFont = header.getFont().deriveFont(Font.BOLD);
+ this.unselectedFont = header.getFont();
+ this.selectedFgColor = UIManager.getColor("textHighlightText");
+ this.unselectedFgColor = header.getForeground();
+ this.unselectedBgColor = header.getBackground().darker();
+
+ Color c = table.getSelectionBackground();
+ float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
+ this.selectedBgColor = Color.getHSBColor(hsb[0], hsb[1] * 2f, hsb[2]);
+
+ setOpaque(true);
+ setBorder(BorderFactory.createEmptyBorder());
+ setHorizontalAlignment(CENTER);
+ setForeground(unselectedFgColor);
+ setBackground(unselectedBgColor);
+ setFont(unselectedFont);
+ if (!rowModel) {
+ setBorder(new AbstractBorder() {
+ public Insets getBorderInsets(Component c) {
+ return INSETS;
+ }
+
+ public Insets getBorderInsets(Component c, Insets insets) {
+ return INSETS;
+ }
+
+ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
+ g.setColor(HeaderRenderer.this.table.getGridColor().darker());
+ g.drawLine(x, y, x + width, y);
+ g.drawLine(x, y, x, y + height);
+ }
+ });
+ }
+ }
+
+ public void paintComponent(Graphics g) {
+ ListSelectionModel lsm;
+ if (rowModel) {
+ lsm = table.getSelectionModel();
+ } else {
+ lsm = table.getColumnModel().getSelectionModel();
+ }
+
+ if (lsm.isSelectedIndex(index)) {
+ setForeground(selectedFgColor);
+ setBackground(selectedBgColor);
+ setFont(selectedFont);
+ } else {
+ setForeground(unselectedFgColor);
+ setBackground(unselectedBgColor);
+ setFont(unselectedFont);
+ }
+
+ super.paintComponent(g);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+ if (rowModel) {
+ this.index = row;
+ } else {
+ this.index = column;
+ }
+
+ setText(Integer.toString(index + 1));
+
+ return this;
+ }
+}
package org.scilab.modules.ui_data.rowheader;
import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
+import javax.swing.BorderFactory;
import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingUtilities;
+import javax.swing.border.AbstractBorder;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+import org.scilab.modules.ui_data.variableeditor.TableVariableEditor;
+import org.scilab.modules.ui_data.variableeditor.actions.InsertRowAction;
+import org.scilab.modules.ui_data.variableeditor.actions.RemoveRowAction;
+
/**
* Class for the RowHeader
* @author Calixte DENIZET
*/
public class RowHeader extends JPanel implements TableModelListener {
+ private static final Insets INSETS = new Insets(1, 0, 0, 0);
+
private JTable rowTable;
+ private JTable table;
private DefaultTableModel model;
+ private int clickedRow;
/**
* Constructor
* @param table the table
*/
- public RowHeader(JTable table) {
+ public RowHeader(final JTable table) {
super(new BorderLayout());
+ this.table = table;
table.getModel().addTableModelListener(this);
- model = new DefaultTableModel(0, 1);
+ model = new DefaultTableModel(0, 1) {
+ public boolean isCellEditable(int iRowIndex, int iColumnIndex) {
+ return false;
+ }
+ };
rowTable = new JTable(model);
- rowTable.setModel(model);
- rowTable.setRowHeight(table.getRowHeight() + table.getRowMargin() - table.getIntercellSpacing().height);
- rowTable.getColumnModel().getColumn(0).setMinWidth(50);
- rowTable.getColumnModel().getColumn(0).setMaxWidth(100);
- rowTable.getColumnModel().getColumn(0).setPreferredWidth(50);
+ setBorder(new AbstractBorder() {
+ public Insets getBorderInsets(Component c) {
+ return INSETS;
+ }
+
+ public Insets getBorderInsets(Component c, Insets insets) {
+ return INSETS;
+ }
- rowTable.setDefaultEditor(Object.class, new RowHeaderCellEditor(table));
- rowTable.setDefaultRenderer(Object.class, new RowHeaderRenderer());
+ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
+ g.setColor(table.getGridColor().darker());
+ g.drawLine(x, y, x + width, y);
+ }
+ });
+ rowTable.setDoubleBuffered(true);
+ rowTable.setDragEnabled(false);
+ rowTable.setGridColor(table.getGridColor().darker());
+ rowTable.setShowVerticalLines(true);
+ rowTable.setModel(model);
+ rowTable.setRowHeight(table.getRowHeight());
+ rowTable.setRowMargin(table.getRowMargin());
+ rowTable.setIntercellSpacing(table.getIntercellSpacing());
+ rowTable.setDefaultEditor(Object.class, null);
+ rowTable.setCellEditor(null);
+ rowTable.setDefaultRenderer(Object.class, new HeaderRenderer(table, true));
+ rowTable.setComponentPopupMenu(createPopupMenu());
rowTable.doLayout();
add(rowTable);
doLayout();
- setBackground(table.getSelectionBackground());
+ rowTable.addMouseListener(new MouseAdapter() {
+ public void mousePressed(MouseEvent e) {
+ if (SwingUtilities.isLeftMouseButton(e)) {
+ int row = rowTable.rowAtPoint(e.getPoint());
+ ListSelectionModel rsm = table.getSelectionModel();
+ if (e.isShiftDown()) {
+ rsm.setSelectionInterval(row, clickedRow);
+ table.setColumnSelectionInterval(0, ((SwingEditvarTableModel) ((TableVariableEditor) table).getModel()).getScilabMatrixColCount() - 1);
+ } else {
+ if ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
+ if (table.isRowSelected(row)) {
+ rsm.removeSelectionInterval(row, row);
+ } else {
+ rsm.addSelectionInterval(row, row);
+ table.setColumnSelectionInterval(0, ((SwingEditvarTableModel) ((TableVariableEditor) table).getModel()).getScilabMatrixColCount() - 1);
+ }
+ } else {
+ rsm.setSelectionInterval(row, row);
+ table.setColumnSelectionInterval(0, ((SwingEditvarTableModel) ((TableVariableEditor) table).getModel()).getScilabMatrixColCount() - 1);
+ }
+ clickedRow = row;
+ }
+ table.requestFocus();
+ }
+ }
+ });
+
+ rowTable.addMouseMotionListener(new MouseMotionAdapter() {
+ public void mouseDragged(MouseEvent e) {
+ if (SwingUtilities.isLeftMouseButton(e)) {
+ Point p = e.getPoint();
+ int row;
+ if (p.y >= rowTable.getCellRect(rowTable.getRowCount() - 1, 0, false).y) {
+ row = rowTable.getRowCount() - 1;
+ } else {
+ row = rowTable.rowAtPoint(p);
+ }
+
+ ListSelectionModel rsm = table.getSelectionModel();
+ int lead = rsm.getLeadSelectionIndex();
+ if (lead != row) {
+ if (row == rowTable.getRowCount() - 1) {
+ ((TableVariableEditor) table).addTenRows();
+ }
+ table.scrollRectToVisible(table.getCellRect(row, 0, false));
+ if (e.isShiftDown()) {
+ rsm.setSelectionInterval(clickedRow, row);
+ } else {
+ if ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
+ if (rsm.isSelectedIndex(row)) {
+ rsm.removeSelectionInterval(lead, row);
+ rsm.addSelectionInterval(clickedRow, row);
+ } else {
+ rsm.addSelectionInterval(clickedRow, row);
+ }
+ } else {
+ rsm.setSelectionInterval(clickedRow, row);
+ }
+ }
+ table.setColumnSelectionInterval(0, ((SwingEditvarTableModel) ((TableVariableEditor) table).getModel()).getScilabMatrixColCount() - 1);
+ table.requestFocus();
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * @return a popup menu for the table
+ */
+ public JPopupMenu createPopupMenu() {
+ JPopupMenu popup = new JPopupMenu() {
+ public void show(Component invoker, int x, int y) {
+ ((TableVariableEditor) table).setPopupRow(rowTable.rowAtPoint(new Point(x, y)));
+ super.show(invoker, x, y);
+ }
+ };
+ popup.setBorderPainted(true);
+ popup.add(InsertRowAction.createMenuItem(table, UiDataMessages.INSERTR));
+ popup.add(RemoveRowAction.createMenuItem(table, UiDataMessages.REMOVER));
+
+ return popup;
}
/**
model.addRow(new Object[1]);
}
}
+
+ /**
+ * @return the JTable used as row header
+ */
+ public JTable getTable() {
+ return rowTable;
+ }
}
package org.scilab.modules.ui_data.rowheader;
-import java.awt.event.ActionEvent;
+import java.awt.Color;
import java.awt.Component;
+import java.awt.Font;
import javax.swing.AbstractAction;
import javax.swing.AbstractCellEditor;
-import javax.swing.JButton;
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
import javax.swing.JTable;
+import javax.swing.UIManager;
+import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellEditor;
/**
*/
public class RowHeaderCellEditor extends AbstractCellEditor implements TableCellEditor {
- private JButton button;
+ private JLabel label;
private int row;
/**
* @param table the table where to put the rowHeader
*/
public RowHeaderCellEditor(final JTable table) {
- button = new JButton();
- button.setFocusPainted(false);
- button.setAction(new AbstractAction() {
- public void actionPerformed(ActionEvent e) {
- table.setRowSelectionInterval(row, row);
- table.setColumnSelectionInterval(0, table.getColumnCount() - 1);
- table.requestFocus();
- }
- });
+ label = new JLabel();
+ JTableHeader header = table.getTableHeader();
+ label.setOpaque(true);
+ label.setBorder(BorderFactory.createEmptyBorder());
+ label.setHorizontalAlignment(JLabel.CENTER);
+ label.setForeground(UIManager.getColor("textHighlightText"));
+ label.setFont(header.getFont().deriveFont(Font.BOLD));
+
+ Color selected = UIManager.getColor("Table.selectionBackground");
+ float[] hsb = Color.RGBtoHSB(selected.getRed(), selected.getGreen(), selected.getBlue(), null);
+ label.setBackground(Color.getHSBColor(hsb[0], 1, hsb[2]));
}
/**
*/
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) {
this.row = row;
- button.setText(Integer.toString(row + 1));
+ label.setText(Integer.toString(row + 1));
- return button;
+ return label;
}
}
package org.scilab.modules.ui_data.rowheader;
+import java.awt.Color;
import java.awt.Component;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
-import javax.swing.JButton;
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.UIManager;
+import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
+import org.scilab.modules.ui_data.rowheader.HeaderRenderer;
+import org.scilab.modules.ui_data.rowheader.RowHeader;
+
/**
* @author Calixte DENIZET
*/
-public class RowHeaderRenderer implements TableCellRenderer {
+public class RowHeaderRenderer extends JLabel implements TableCellRenderer {
- private JButton button;
- private int row;
+ private int index;
+ private JTable table;
+ private boolean rowModel;
/**
* Constructor
*/
- public RowHeaderRenderer() {
- button = new JButton();
+ public RowHeaderRenderer(JTable table, boolean rowModel) {
+ this.table = table;
+ this.rowModel = rowModel;
+ JTableHeader header = table.getTableHeader();
+ setOpaque(true);
+ setBorder(BorderFactory.createEmptyBorder());
+ setHorizontalAlignment(CENTER);
+ setForeground(header.getForeground());
+ setBackground(header.getBackground());
+ setFont(header.getFont());
+ if (!rowModel) {
+ setBorder(BorderFactory.createLineBorder(table.getGridColor().darker(), 1));
+ }
+ }
+
+ public void paintComponent(Graphics g) {
+ JTableHeader header = table.getTableHeader();
+ ListSelectionModel lsm;
+ if (rowModel) {
+ lsm = table.getSelectionModel();
+ } else {
+ lsm = table.getColumnModel().getSelectionModel();
+ }
+
+ if (lsm.isSelectedIndex(index)) {
+ Color c = UIManager.getColor("Table.selectionBackground");
+ float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
+ setBackground(Color.getHSBColor(hsb[0], 1, hsb[2]));
+ setFont(header.getFont().deriveFont(Font.BOLD));
+ setForeground(UIManager.getColor("textHighlightText"));
+ } else {
+ setForeground(header.getForeground());
+ setBackground(header.getBackground());
+ setFont(header.getFont());
+ }
+ super.paintComponent(g);
}
/**
* {@inheritDoc}
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
- this.row = row;
- button.setText(Integer.toString(row + 1));
+ if (rowModel) {
+ this.index = row;
+ } else {
+ this.index = column;
+ }
- return button;
+ setText(Integer.toString(index + 1));
+
+ return this;
}
}
public static final String GLOBAL_NOT_EDITABLE = Messages.gettext("Global variables can not be edited.");
+ public static final String EDITION = Messages.gettext("Edition");
public static final String REFRESH = Messages.gettext("Refresh the variable ");
public static final String COPY = Messages.gettext("Copy");
public static final String PASTE = Messages.gettext("Paste");
public static final String CLEAR = Messages.gettext("Clear");
public static final String UNDO = Messages.gettext("Undo");
public static final String REDO = Messages.gettext("Redo");
+ public static final String FIT = Messages.gettext("Size columns to fit");
+ public static final String COPYASSCILABCOM = Messages.gettext("Copy as Scilab command");
+ public static final String COPYASSCILABMAT = Messages.gettext("Copy as Scilab matrix");
+ public static final String COPYASSCILABMATWITHCR = Messages.gettext("Copy as Scilab matrix with CR");
+
+ public static final String SHORT = Messages.gettext("Short format");
+ public static final String SHORTE = Messages.gettext("ShortE format");
+ public static final String LONG = Messages.gettext("Long format");
+ public static final String LONGE = Messages.gettext("LongE format");
+
+ public static final String CREATE = Messages.gettext("Create variable from selection");
+
+ public static final String INSERTR = Messages.gettext("Insert a row");
+ public static final String REMOVER = Messages.gettext("Remove rows");
+ public static final String INSERTC = Messages.gettext("Insert a column");
+ public static final String REMOVEC = Messages.gettext("Remove columns");
+
+ public static final String PLOTSELECTION = Messages.gettext("Plot the selection");
+ public static final String PLOTALL = Messages.gettext("Plot the matrix");
+
+ public static final String CANCEL = Messages.gettext("Cancel");
+ public static final String OK = Messages.gettext("Ok");
+ public static final String CREATEVAR = Messages.gettext("Create variable from selection");
+ public static final String VARNAME = Messages.gettext("Variable name");
+ public static final String CREATENEWVAR = Messages.gettext("Create new variable");
+ public static final String DUPLICATE = Messages.gettext("Duplicate the variable");
+ public static final String NUMROWS = Messages.gettext("Rows number");
+ public static final String NUMCOLS = Messages.gettext("Columns number");
+ public static final String FILLWITH = Messages.gettext("Fill with");
public static final String FILE_BROWSER = Messages.gettext("File Browser");
public static final String NAME_COLUMN = Messages.gettext("Name");
- // CSON: JavadocVariable
- // CSON: LineLength
- // CSON: MultipleStringLiterals
+ // CSON: JavadocVariable
+ // CSON: LineLength
+ // CSON: MultipleStringLiterals
/**
* This function checks for the popup menu activation under MacOS with Java version 1.5
* @param e Click event
* @return true if Java 1.5 and MacOS and mouse clic and ctrl activated
*/
- public static boolean isMacOsPopupTrigger(MouseEvent e) {
- return (SwingUtilities.isLeftMouseButton(e)
- && e.isControlDown()
- && (System.getProperty("os.name").toLowerCase().indexOf("mac") != -1) && (System
- .getProperty("java.specification.version").equals("1.5")));
- }
+ public static boolean isMacOsPopupTrigger(MouseEvent e) {
+ return (SwingUtilities.isLeftMouseButton(e)
+ && e.isControlDown()
+ && (System.getProperty("os.name").toLowerCase().indexOf("mac") != -1) && (System.getProperty("java.specification.version").equals("1.5")));
+ }
}
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.io.IOException;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
+import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
DragSource dragsource = DragSource.getDefaultDragSource();
dragsource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this);
DropTarget droptarget = new DropTarget(this, this);
+ addFocusListener(new FocusAdapter() {
+ public void focusGained(FocusEvent e) {
+ ((JScrollPane) getComponentAt(getSelectedIndex())).getViewport().getView().requestFocus();
+ }
+ });
}
/**
package org.scilab.modules.ui_data.variableeditor;
import java.awt.Component;
+import java.util.HashMap;
import java.util.Map;
-import java.util.WeakHashMap;
+import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeListener;
private static final String MENUBARXMLFILE = System.getenv("SCI") + "/modules/ui_data/etc/variableeditor_menubar.xml";
- private static Map<String, Component> map = new WeakHashMap();
+ private static Map<String, Component> map = new HashMap();
private static VariableEditor instance;
tabPane = ((SwingScilabVariableEditor) editorTab).getTabPane();
editorTab.setCallback(ScilabCallBack.createCallback("org.scilab.modules.ui_data.EditVar.closeVariableEditor",
ScilabCallBack.JAVA_OUT_OF_XCLICK_AND_XGETMOUSE));
- MenuBar menubar = MenuBarBuilder.buildMenuBar(MENUBARXMLFILE);
- editorTab.addMenuBar(menubar);
TextBox infobar = ScilabTextBox.createTextBox();
editorTab.addInfoBar(infobar);
editorTab.close();
instance = null;
map.clear();
- CellsUndoableEdit.clear();
}
/**
*/
public static void close(String name) {
map.remove(name);
- CellsUndoableEdit.removeVar(name);
}
/**
}
/**
+ * Set data displayed in JTable
+ * @param name the variable name
+ * @param type the variable type
+ * @param data : data to be displayed in JTable
+ */
+ public void updateData(String name, String type, Object[][] data, double[] rowsIndex, double[] colsIndex) {
+ if (map.containsKey(name)) {
+ ((SwingScilabVariableEditor) editorTab).updateData(map.get(name), name, type, data, rowsIndex, colsIndex);
+ }
+ }
+
+ /**
* Get the variable editor singleton
* @return the Variable Editor
*/
SwingScilabWindow window = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, (SwingScilabVariableEditor) editorTab);
window.setVisible(true);
window.toFront();
- int row = -1;
- int col = -1;
- SwingEditvarTableModel model = (SwingEditvarTableModel) ((SwingScilabVariableEditor) editorTab).getCurrentModel();
- if (model != null) {
- row = model.getCurrentRow();
- col = model.getCurrentCol();
- }
- final int r = row;
- final int c = col;
- SwingUtilities.invokeLater(new Thread() {
+ final JTable table = ((SwingScilabVariableEditor) editorTab).getCurrentTable();
+ SwingUtilities.invokeLater(new Runnable() {
public void run() {
+ int r = -1;
+ int c = -1;
+
+ if (table != null) {
+ r = table.getSelectedRow();
+ c = table.getSelectedColumn();
+ }
+ boolean b = map.containsKey(variableName);
instance.updateData(variableName, type, data);
- if (r != -1 && c != -1) {
- ((SwingScilabVariableEditor) editorTab).getCurrentTable().setRowSelectionInterval(r, r);
- ((SwingScilabVariableEditor) editorTab).getCurrentTable().setColumnSelectionInterval(c, c);
+ if (b && r != -1 && c != -1) {
+ table.setRowSelectionInterval(r, r);
+ table.setColumnSelectionInterval(c, c);
}
}
});
return instance;
}
+ public static void refreshVariableEditor(final String type, final Object[][] data, double[] rowsIndex, double[] colsIndex, final String variableName) {
+ if (instance != null) {
+ instance.updateData(variableName, type, data, rowsIndex, colsIndex);
+ }
+ }
+
/**
* {@inheritDoc}
*/
package org.scilab.modules.ui_data.variableeditor;
-import java.awt.Color;
import java.awt.Component;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
+import javax.swing.JMenu;
+import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
-import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
+import org.scilab.modules.gui.menu.Menu;
+import org.scilab.modules.gui.menu.ScilabMenu;
import org.scilab.modules.gui.menubar.MenuBar;
+import org.scilab.modules.gui.menubar.ScilabMenuBar;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.gui.tab.SimpleTab;
import org.scilab.modules.gui.tab.Tab;
import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
import org.scilab.modules.ui_data.rowheader.RowHeader;
import org.scilab.modules.ui_data.utils.UiDataMessages;
+import org.scilab.modules.ui_data.variableeditor.actions.CloseAction;
import org.scilab.modules.ui_data.variableeditor.actions.CopyAction;
+import org.scilab.modules.ui_data.variableeditor.actions.CopySelectionAsScilabCommandAction;
+import org.scilab.modules.ui_data.variableeditor.actions.CopySelectionAsScilabMatrixAction;
+import org.scilab.modules.ui_data.variableeditor.actions.CopySelectionAsScilabMatrixWithCRAction;
+import org.scilab.modules.ui_data.variableeditor.actions.CreateNewVariableAction;
+import org.scilab.modules.ui_data.variableeditor.actions.CreateVariableFromSelectionAction;
import org.scilab.modules.ui_data.variableeditor.actions.CutAction;
+import org.scilab.modules.ui_data.variableeditor.actions.DuplicateVariableAction;
import org.scilab.modules.ui_data.variableeditor.actions.PasteAction;
+import org.scilab.modules.ui_data.variableeditor.actions.PlotAction;
import org.scilab.modules.ui_data.variableeditor.actions.RedoAction;
import org.scilab.modules.ui_data.variableeditor.actions.RefreshAction;
+import org.scilab.modules.ui_data.variableeditor.actions.SetPrecisionShortAction;
+import org.scilab.modules.ui_data.variableeditor.actions.SetPrecisionShorteAction;
+import org.scilab.modules.ui_data.variableeditor.actions.SetPrecisionLongAction;
+import org.scilab.modules.ui_data.variableeditor.actions.SetPrecisionLongeAction;
+import org.scilab.modules.ui_data.variableeditor.actions.SizeColumnsToFitAction;
import org.scilab.modules.ui_data.variableeditor.actions.SupprAction;
import org.scilab.modules.ui_data.variableeditor.actions.UndoAction;
import org.scilab.modules.ui_data.variableeditor.renderers.RendererFactory;
private static final String APOS = "'";
private static final long serialVersionUID = 1L;
- private SwingEditvarTableModel dataModel;
private ScilabTabbedPane tabPane;
- private JScrollPane scrollPane;
private PushButton refreshButton;
private PushButton undoButton;
private PushButton redoButton;
});
setContentPane(tabPane);
setData(name, type, data);
- ToolBar toolBar = ScilabToolBar.createToolBar();
- toolBar.add(refreshButton);
- toolBar.addSeparator();
- toolBar.add(CutAction.createButton(this, UiDataMessages.CUT));
- toolBar.add(CopyAction.createButton(this, UiDataMessages.COPY));
- toolBar.add(PasteAction.createButton(this, UiDataMessages.PASTE));
- toolBar.addSeparator();
- toolBar.add(undoButton);
- toolBar.add(redoButton);
- addToolBar(toolBar);
WindowsConfigurationManager.restorationFinished(this);
+
+ addToolBar(createToolBar());
+ addMenuBar(createMenuBar());
}
/**
}
/**
+ * Create the toolbar
+ * @return the built toolbar
+ */
+ public ToolBar createToolBar() {
+ ToolBar toolBar = ScilabToolBar.createToolBar();
+ toolBar.add(refreshButton);
+ toolBar.addSeparator();
+ toolBar.add(CreateVariableFromSelectionAction.createButton(this, UiDataMessages.CREATE));
+ toolBar.add(CreateNewVariableAction.createButton(this, UiDataMessages.CREATENEWVAR));
+ toolBar.addSeparator();
+ toolBar.add(CutAction.createButton(this, UiDataMessages.CUT));
+ toolBar.add(CopyAction.createButton(this, UiDataMessages.COPY));
+ toolBar.add(PasteAction.createButton(this, UiDataMessages.PASTE));
+ toolBar.addSeparator();
+ toolBar.add(undoButton);
+ toolBar.add(redoButton);
+ toolBar.addSeparator();
+ toolBar.add(SizeColumnsToFitAction.createButton(this, UiDataMessages.FIT));
+ toolBar.addSeparator();
+ toolBar.add(SetPrecisionShortAction.createButton(this, UiDataMessages.SHORT));
+ toolBar.add(SetPrecisionShorteAction.createButton(this, UiDataMessages.SHORTE));
+ toolBar.add(SetPrecisionLongAction.createButton(this, UiDataMessages.LONG));
+ toolBar.add(SetPrecisionLongeAction.createButton(this, UiDataMessages.LONGE));
+ toolBar.addSeparator();
+ toolBar.add(PlotAction.createButton(this, UiDataMessages.PLOTSELECTION));
+
+ return toolBar;
+ }
+
+ /**
+ * @return a popup menu for the table
+ */
+ public JPopupMenu createPopupMenu() {
+ JPopupMenu popup = new JPopupMenu();
+ popup.setBorderPainted(true);
+ popup.add(UndoAction.createJMenuItem(this, UiDataMessages.UNDO));
+ popup.add(RedoAction.createJMenuItem(this, UiDataMessages.REDO));
+ popup.addSeparator();
+ popup.add(CutAction.createJMenuItem(this, UiDataMessages.CUT));
+ popup.add(CopyAction.createJMenuItem(this, UiDataMessages.COPY));
+ popup.add(PasteAction.createJMenuItem(this, UiDataMessages.PASTE));
+ popup.addSeparator();
+ popup.add(CopySelectionAsScilabCommandAction.createJMenuItem(this, UiDataMessages.COPYASSCILABCOM));
+ popup.add(CopySelectionAsScilabMatrixAction.createJMenuItem(this, UiDataMessages.COPYASSCILABMAT));
+ popup.add(CopySelectionAsScilabMatrixWithCRAction.createJMenuItem(this, UiDataMessages.COPYASSCILABMATWITHCR));
+ popup.addSeparator();
+ popup.add(CreateVariableFromSelectionAction.createJMenuItem(this, UiDataMessages.CREATE));
+ popup.add(CreateNewVariableAction.createJMenuItem(this, UiDataMessages.CREATENEWVAR));
+ popup.add(DuplicateVariableAction.createJMenuItem(this, UiDataMessages.DUPLICATE));
+
+ popup.addSeparator();
+
+ JMenu plots = new JMenu(UiDataMessages.PLOTSELECTION);
+ popup.add(plots);
+
+ plots.add(PlotAction.createJMenuItem(this, "plot2d", true));
+ plots.add(PlotAction.createJMenuItem(this, "Matplot", true));
+ plots.add(PlotAction.createJMenuItem(this, "grayplot", true));
+ plots.add(PlotAction.createJMenuItem(this, "Sgrayplot", true));
+ plots.add(PlotAction.createJMenuItem(this, "champ", true));
+ plots.add(PlotAction.createJMenuItem(this, "histplot", true));
+ plots.add(PlotAction.createJMenuItem(this, "mesh", true));
+ plots.add(PlotAction.createJMenuItem(this, "surf", true));
+ plots.add(PlotAction.createJMenuItem(this, "hist3d", true));
+ plots.add(PlotAction.createJMenuItem(this, "contour2d", true));
+ plots.add(PlotAction.createJMenuItem(this, "pie", true));
+
+ popup.addSeparator();
+
+ JMenu plotAll = new JMenu(UiDataMessages.PLOTALL);
+ popup.add(plotAll);
+
+ plotAll.add(PlotAction.createJMenuItem(this, "plot2d", false));
+ plotAll.add(PlotAction.createJMenuItem(this, "Matplot", false));
+ plotAll.add(PlotAction.createJMenuItem(this, "grayplot", false));
+ plotAll.add(PlotAction.createJMenuItem(this, "Sgrayplot", false));
+ plotAll.add(PlotAction.createJMenuItem(this, "champ", false));
+ plotAll.add(PlotAction.createJMenuItem(this, "histplot", false));
+ plotAll.add(PlotAction.createJMenuItem(this, "mesh", false));
+ plotAll.add(PlotAction.createJMenuItem(this, "surf", false));
+ plotAll.add(PlotAction.createJMenuItem(this, "hist3d", false));
+ plotAll.add(PlotAction.createJMenuItem(this, "contour2d", false));
+ plotAll.add(PlotAction.createJMenuItem(this, "pie", false));
+
+ return popup;
+ }
+
+ public MenuBar createMenuBar() {
+ MenuBar bar = ScilabMenuBar.createMenuBar();
+ Menu file = ScilabMenu.createMenu();
+ file.setText(UiDataMessages.FILE);
+ file.add(CreateVariableFromSelectionAction.createMenuItem(this, UiDataMessages.CREATE));
+ file.add(CreateNewVariableAction.createMenuItem(this, UiDataMessages.CREATENEWVAR));
+ file.add(DuplicateVariableAction.createMenuItem(this, UiDataMessages.DUPLICATE));
+ file.addSeparator();
+ file.add(CloseAction.createMenuItem(this, UiDataMessages.CLOSE));
+
+ bar.add(file);
+ Menu edition = ScilabMenu.createMenu();
+ edition.setText(UiDataMessages.EDITION);
+ edition.add(UndoAction.createMenuItem(this, UiDataMessages.UNDO));
+ edition.add(RedoAction.createMenuItem(this, UiDataMessages.REDO));
+ edition.addSeparator();
+ edition.add(CutAction.createMenuItem(this, UiDataMessages.CUT));
+ edition.add(CopyAction.createMenuItem(this, UiDataMessages.COPY));
+ edition.add(PasteAction.createMenuItem(this, UiDataMessages.PASTE));
+ edition.addSeparator();
+ edition.add(CopySelectionAsScilabCommandAction.createMenuItem(this, UiDataMessages.COPYASSCILABCOM));
+ edition.add(CopySelectionAsScilabMatrixAction.createMenuItem(this, UiDataMessages.COPYASSCILABMAT));
+ edition.add(CopySelectionAsScilabMatrixWithCRAction.createMenuItem(this, UiDataMessages.COPYASSCILABMATWITHCR));
+ edition.addSeparator();
+ edition.add(SizeColumnsToFitAction.createMenuItem(this, UiDataMessages.FIT));
+ bar.add(edition);
+
+ return bar;
+ }
+
+ /**
* {@inheritDoc}
*/
public void setData(String name, String type, Object[][] data) {
- final JTable table = new JTable();
- table.getTableHeader().addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent evt) {
- int column = table.getColumnModel().getColumnIndexAtX(evt.getX());
- table.setColumnSelectionInterval(column, column);
- table.setRowSelectionInterval(0, table.getRowCount() - 1);
- table.requestFocus();
- }
- });
- table.getTableHeader().setReorderingAllowed(false);
+ TableVariableEditor table = new TableVariableEditor(this);
CopyAction.registerAction(this, table);
CutAction.registerAction(this, table);
SupprAction.registerAction(this, table);
UndoAction.registerAction(this, table);
RedoAction.registerAction(this, table);
+ SizeColumnsToFitAction.registerAction(this, table);
+ SetPrecisionShortAction.registerAction(this, table);
+ SetPrecisionShorteAction.registerAction(this, table);
+ SetPrecisionLongAction.registerAction(this, table);
+ SetPrecisionLongeAction.registerAction(this, table);
+ CreateVariableFromSelectionAction.registerAction(this, table);
+ CreateNewVariableAction.registerAction(this, table);
- scrollPane = new JScrollPane(table);
- table.setFillsViewportHeight(true);
- table.setAutoResizeMode(CENTER);
- table.setRowHeight(25);
- scrollPane.setRowHeaderView(new RowHeader(table));
+ table.setComponentPopupMenu(createPopupMenu());
- updateData(table, name, type, data);
+ ScilabGenericCellEditor cellEditor = (ScilabGenericCellEditor) CellEditorFactory.createCellEditor(type);
+ int rows = Math.max(((TableVariableEditor) table).getMinimalRowNumber(), table.getModel().getRowCount());
+ int cols = table.getModel().getColumnCount();
- table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
- table.setCellSelectionEnabled(true);
+ SwingEditvarTableModel dataModel = new SwingEditvarTableModel(this, name, type, data, cellEditor, rows, cols);
- table.setBackground(Color.WHITE);
- tabPane.add(PREFIX + name, scrollPane);
- tabPane.setSelectedComponent(scrollPane);
+ dataModel.addTableModelListener(getRowHeader((TableVariableEditor) table));
+ getRowHeader((TableVariableEditor) table).tableChanged(new TableModelEvent(dataModel));
+ table.setModel(dataModel);
+ table.setDefaultEditor(Object.class, cellEditor);
+ table.setDefaultRenderer(Object.class, RendererFactory.createRenderer(type));
+
+ tabPane.add(PREFIX + name, table.getScrollPane());
+ tabPane.setSelectedComponent(table.getScrollPane());
}
/**
*/
public void updateData(JTable table, String name, String type, Object[][] data) {
ScilabGenericCellEditor cellEditor = (ScilabGenericCellEditor) CellEditorFactory.createCellEditor(type);
+ int rows = Math.max(((TableVariableEditor) table).getMinimalRowNumber(), table.getModel().getRowCount());
+ int cols = table.getModel().getColumnCount();
CellsUndoManager undo = null;
if (table.getModel() instanceof SwingEditvarTableModel) {
- cellEditor.setExpressions(((SwingEditvarTableModel) table.getModel()).getCellEditor().getExpressions());
undo = ((SwingEditvarTableModel) table.getModel()).getUndoManager();
}
- dataModel = new SwingEditvarTableModel(this, name, type, data, cellEditor);
- dataModel.addTableModelListener(getRowHeader());
- if (undo != null) {
- dataModel.setUndoManager(undo);
- }
- getRowHeader().tableChanged(new TableModelEvent(dataModel));
- table.setModel(dataModel);
+
+ SwingEditvarTableModel dataModel = (SwingEditvarTableModel) table.getModel();
+ getRowHeader((TableVariableEditor) table).tableChanged(new TableModelEvent(dataModel));
+ dataModel.changeData(type, data, cellEditor, rows, cols);
table.setDefaultEditor(Object.class, cellEditor);
table.setDefaultRenderer(Object.class, RendererFactory.createRenderer(type));
}
/**
+ * @param table the table to update
+ * @param name the name of the variable
+ * @param type the type of the matrix
+ * @param data the matrix datas
+ */
+ public void updateData(JTable table, String name, String type, Object[][] data, double[] rowsIndex, double[] colsIndex) {
+ SwingEditvarTableModel dataModel = (SwingEditvarTableModel) table.getModel();
+ if (!type.equals(dataModel.getType())) {
+ dataModel.refresh();
+ } else {
+ for (int i = 0; i < rowsIndex.length; i++) {
+ for (int j = 0; j < colsIndex.length; j++) {
+ int r = (int) rowsIndex[i] - 1;
+ int c = (int) colsIndex[j] - 1;
+ dataModel.setValueAtAndUpdate(false, false, data[i][j], r, c);
+ }
+ }
+ }
+ }
+
+ /**
* @param c the component in the tabbedpane
* @param name the name of the variable
* @param type the type of the matrix
}
/**
+ * @param c the component in the tabbedpane
+ * @param name the name of the variable
+ * @param type the type of the matrix
+ * @param data the matrix datas
+ */
+ public void updateData(Component c, String name, String type, Object[][] data, double[] rowsIndex, double[] colsIndex) {
+ tabPane.setSelectedComponent(c);
+ JTable table = (JTable) ((JScrollPane) c).getViewport().getComponent(0);
+ updateData(table, name, type, data, rowsIndex, colsIndex);
+ }
+
+ /**
* @return the row header used in this table
*/
- public RowHeader getRowHeader() {
- return (RowHeader) scrollPane.getRowHeader().getView();
+ public RowHeader getRowHeader(TableVariableEditor table) {
+ return (RowHeader) table.getScrollPane().getRowHeader().getView();
}
/**
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.AdjustmentListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
+import java.util.Arrays;
+import java.util.Vector;
+
+import javax.swing.BoundedRangeModel;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.TableModelEvent;
+import javax.swing.table.JTableHeader;
+import javax.swing.table.TableColumn;
+
+import org.scilab.modules.gui.textbox.SimpleTextBox;
+import org.scilab.modules.gui.textbox.TextBox;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.rowheader.HeaderRenderer;
+import org.scilab.modules.ui_data.rowheader.RowHeader;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+import org.scilab.modules.ui_data.variableeditor.actions.InsertColumnAction;
+import org.scilab.modules.ui_data.variableeditor.actions.RemoveColumnAction;
+
+/**
+ * The table
+ * @author Calixte DENIZET
+ */
+public class TableVariableEditor extends JTable {
+
+ private JScrollPane scrollPane;
+ private int clickedColumn;
+ private int[] selectedRows = new int[0];
+ private int[] selectedCols = new int[0];
+ private int popupRow;
+ private int popupCol;
+ private SwingScilabVariableEditor editor;
+
+ /**
+ * Default constructor
+ */
+ public TableVariableEditor(SwingScilabVariableEditor editor) {
+ super();
+ this.editor = editor;
+ scrollPane = new JScrollPane(this);
+ /* Modify the table size when the knob is at the bottom of the vertical scrollbar */
+ scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
+ public void adjustmentValueChanged(AdjustmentEvent e) {
+ BoundedRangeModel brm = scrollPane.getVerticalScrollBar().getModel();
+ if (brm.getMaximum() - brm.getExtent() - e.getValue() <= 1) {
+ addTenRows();
+ }
+ }
+ });
+
+ /* Modify the table size when the knob is at the right of the horizontal scrollbar */
+ scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
+ public void adjustmentValueChanged(AdjustmentEvent e) {
+ BoundedRangeModel brm = scrollPane.getHorizontalScrollBar().getModel();
+ if (brm.getMaximum() - brm.getExtent() - e.getValue() <= 1) {
+ addTenCols();
+ }
+ }
+ });
+
+ /* Modify the table size when the scrollpane is resized */
+ scrollPane.getViewport().addComponentListener(new ComponentAdapter() {
+ public void componentResized(ComponentEvent e) {
+ if (((SwingEditvarTableModel) getModel()).enlarge(getMinimalRowNumber() + 1, getMinimalColumnNumber() + 1)) {
+ ((SwingEditvarTableModel) getModel()).fireTableChanged(new TableModelEvent(getModel()));
+ }
+ }
+ });
+
+ getTableHeader().setDefaultRenderer(new HeaderRenderer(this, false));
+
+ /* Handle left click on the column header */
+ getTableHeader().addMouseListener(new MouseAdapter() {
+ public void mousePressed(MouseEvent e) {
+ if (getTableHeader().getCursor().getType() == Cursor.DEFAULT_CURSOR && SwingUtilities.isLeftMouseButton(e)) {
+ JTable table = TableVariableEditor.this;
+ int column = table.getColumnModel().getColumnIndexAtX(e.getX());
+ ListSelectionModel csm = table.getColumnModel().getSelectionModel();
+ if (e.isShiftDown()) {
+ csm.setSelectionInterval(column, clickedColumn);
+ table.setRowSelectionInterval(0, ((SwingEditvarTableModel) getModel()).getScilabMatrixRowCount() - 1);
+ } else {
+ if ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
+ if (table.isColumnSelected(column)) {
+ csm.removeSelectionInterval(column, column);
+ } else {
+ csm.addSelectionInterval(column, column);
+ table.setRowSelectionInterval(0, ((SwingEditvarTableModel) getModel()).getScilabMatrixRowCount() - 1);
+ }
+ } else {
+ csm.setSelectionInterval(column, column);
+ table.setRowSelectionInterval(0, ((SwingEditvarTableModel) getModel()).getScilabMatrixRowCount() - 1);
+ }
+ clickedColumn = column;
+ }
+ table.requestFocus();
+ }
+ }
+ });
+
+ /* Handle left-click drag on the column header */
+ getTableHeader().addMouseMotionListener(new MouseMotionAdapter() {
+ public void mouseDragged(MouseEvent e) {
+ if (getTableHeader().getCursor().getType() == Cursor.DEFAULT_CURSOR && SwingUtilities.isLeftMouseButton(e)) {
+ JTable table = TableVariableEditor.this;
+ Point p = e.getPoint();
+ int column;
+ if (p.x >= table.getTableHeader().getHeaderRect(table.getColumnCount() - 1).x) {
+ column = table.getColumnCount() - 1;
+ } else {
+ column = table.getColumnModel().getColumnIndexAtX(p.x);
+ }
+
+ ListSelectionModel csm = table.getColumnModel().getSelectionModel();
+ int lead = csm.getLeadSelectionIndex();
+ if (lead != column) {
+ if (column == getColumnCount() - 1) {
+ ((TableVariableEditor) table).addTenCols();
+ }
+ table.scrollRectToVisible(table.getTableHeader().getHeaderRect(column));
+ if (e.isShiftDown()) {
+ csm.setSelectionInterval(clickedColumn, column);
+ } else {
+ if ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
+ if (csm.isSelectedIndex(column)) {
+ csm.removeSelectionInterval(lead, column);
+ csm.addSelectionInterval(clickedColumn, column);
+ } else {
+ csm.addSelectionInterval(clickedColumn, column);
+ }
+ } else {
+ csm.setSelectionInterval(clickedColumn, column);
+ }
+ }
+ table.setRowSelectionInterval(0, ((SwingEditvarTableModel) getModel()).getScilabMatrixRowCount() - 1);
+ table.requestFocus();
+ }
+ }
+ }
+ });
+
+ getTableHeader().setReorderingAllowed(false);
+ getTableHeader().setComponentPopupMenu(createPopupMenu());
+
+ /* Click on the upper left corner selects all */
+ scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, new JPanel());
+ scrollPane.getCorner(JScrollPane.UPPER_LEFT_CORNER).addMouseListener(new MouseAdapter() {
+ public void mousePressed(MouseEvent e) {
+ selectAll();
+ }
+ });
+
+ /* Click on the lower left corner clear the selection */
+ scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, new JPanel());
+ scrollPane.getCorner(JScrollPane.LOWER_LEFT_CORNER).addMouseListener(new MouseAdapter() {
+ public void mousePressed(MouseEvent e) {
+ clearSelection();
+ }
+ });
+
+ setFillsViewportHeight(true);
+ setRowHeight(18);
+ scrollPane.setRowHeaderView(new RowHeader(this));
+ setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+ setCellSelectionEnabled(true);
+ setBackground(Color.WHITE);
+ setAutoResizeMode(AUTO_RESIZE_OFF);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void valueChanged(ListSelectionEvent e) {
+ int[] rows = getSelectedRows();
+ Vector<Integer> rowDiff = getDifference(rows, selectedRows);
+ JTable rowHeader = ((RowHeader) scrollPane.getRowHeader().getView()).getTable();
+ for (int i : rowDiff) {
+ rowHeader.repaint(rowHeader.getCellRect(i, 0, false));
+ }
+ selectedRows = rows;
+ SwingEditvarTableModel model = (SwingEditvarTableModel) getModel();
+ editor.getInfoBar().getAsSimpleTextBox().setText(model.getScilabSubMatrix(rows, getSelectedColumns()));
+
+ super.valueChanged(e);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void columnSelectionChanged(ListSelectionEvent e) {
+ int[] cols = getSelectedColumns();
+ Vector<Integer> colDiff = getDifference(cols, selectedCols);
+ JTableHeader colHeader = getTableHeader();
+ for (int i : colDiff) {
+ colHeader.repaint(colHeader.getHeaderRect(i));
+ }
+ selectedCols = cols;
+ SwingEditvarTableModel model = (SwingEditvarTableModel) getModel();
+ editor.getInfoBar().getAsSimpleTextBox().setText(model.getScilabSubMatrix(getSelectedRows(), cols));
+
+ super.columnSelectionChanged(e);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void selectAll() {
+ /* Just select the matrix not all the table */
+ SwingEditvarTableModel model = (SwingEditvarTableModel) getModel();
+ int rowC = model.getScilabMatrixRowCount() - 1;
+ int colC = model.getScilabMatrixColCount() - 1;
+ setColumnSelectionInterval(0, colC);
+ setRowSelectionInterval(0, rowC);
+ }
+
+ /**
+ * @return a popup menu for the column header
+ */
+ public JPopupMenu createPopupMenu() {
+ JPopupMenu popup = new JPopupMenu() {
+ public void show(Component invoker, int x, int y) {
+ setPopupColumn(getColumnModel().getColumnIndexAtX(x));
+ super.show(invoker, x, y);
+ }
+ };
+ popup.setBorderPainted(true);
+ popup.add(InsertColumnAction.createMenuItem(this, UiDataMessages.INSERTC));
+ popup.add(RemoveColumnAction.createMenuItem(this, UiDataMessages.REMOVEC));
+
+ return popup;
+ }
+
+ /**
+ * @return the scrollpane used to display this table
+ */
+ public JScrollPane getScrollPane() {
+ return scrollPane;
+ }
+
+ /**
+ * @return the minimal row number according to the table size
+ */
+ public int getMinimalRowNumber() {
+ Dimension dim = scrollPane.getViewport().getSize();
+ return (int) ((double) dim.height / getRowHeight()) + 1;
+ }
+
+ /**
+ * @return the minimal column number according to the table size
+ */
+ public int getMinimalColumnNumber() {
+ Dimension dim = scrollPane.getViewport().getSize();
+ return (int) ((double) dim.width / 75) + 1;
+ }
+
+ /**
+ * Add ten rows
+ */
+ public void addTenRows() {
+ int rowCount = getRowCount();
+ ((SwingEditvarTableModel) getModel()).addRows(10);
+ ((SwingEditvarTableModel) getModel()).fireTableRowsInserted(rowCount, rowCount + 10);
+ }
+
+ /**
+ * Add ten columns
+ */
+ public void addTenCols() {
+ ((SwingEditvarTableModel) getModel()).addColumns(10);
+ int count = getColumnCount();
+ for (int i = count; i < count + 10; i++) {
+ addColumn(new TableColumn(i));
+ }
+ }
+
+ /**
+ * Resize the columns to fit contents
+ */
+ public void sizeColumnsToFit() {
+ SwingEditvarTableModel model = (SwingEditvarTableModel) getModel();
+ for (int i = 0; i < model.getScilabMatrixColCount(); i++) {
+ TableColumn col = getColumnModel().getColumn(i);
+ int width = 75;
+ for (int j = 0; j < model.getScilabMatrixRowCount(); j++) {
+ Component c = getCellRenderer(j, i).getTableCellRendererComponent(this, getValueAt(j, i), false, false, j, i);
+ if (c instanceof JLabel) {
+ JLabel label = (JLabel) c;
+ String text = label.getText();
+ if (text != null && !text.isEmpty()) {
+ int trueWidth = SwingUtilities.computeStringWidth(label.getFontMetrics(label.getFont()), label.getText());
+ width = Math.max(width, trueWidth);
+ }
+ }
+ }
+ if (width != 75) {
+ col.setPreferredWidth(width + 20);
+ } else {
+ col.setPreferredWidth(75);
+ }
+ }
+ invalidate();
+ doLayout();
+ repaint();
+ }
+
+ /**
+ * Set the row where a jpopupmenu has been shown
+ * @param r the row index
+ */
+ public void setPopupRow(int r) {
+ popupRow = r;
+ }
+
+ /**
+ * Get the row index where a jpopupmenu has been shown
+ * @return the row index
+ */
+ public int getPopupRow() {
+ return popupRow;
+ }
+
+ /**
+ * Set the column where a jpopupmenu has been shown
+ * @param r the column index
+ */
+ public void setPopupColumn(int c) {
+ popupCol = c;
+ }
+
+ /**
+ * Get the column index where a jpopupmenu has been shown
+ * @return the column index
+ */
+ public int getPopupColumn() {
+ return popupCol;
+ }
+
+ /**
+ * Computes the symmetric difference between the sorted arrays a and b
+ */
+ private Vector<Integer> getDifference(int[] a, int[] b) {
+ Vector<Integer> v = new Vector<Integer>(a.length + b.length);
+ for (int i : a) {
+ if (Arrays.binarySearch(b, i) < 0) {
+ v.add(i);
+ }
+ }
+ for (int i : b) {
+ if (Arrays.binarySearch(a, i) < 0) {
+ v.add(i);
+ }
+ }
+
+ return v;
+ }
+}
void updateData(String name, String type, Object[][] data);
/**
+ * Set Data stored in JTable.
+ * @param name the name of the Scilab var
+ * @param type the type of the var
+ * @param data : the data to be stored.
+ */
+ void updateData(String name, String type, Object[][] data, double[] rowsIndex, double[] colsIndex);
+
+ /**
* Set the name of the variable being edited in Editvar
* @param variableName : name of the variable being edited.
*/
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.ui_data.EditVar;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+
+/**
+ * CloseAction class
+ * @author Calixte DENIZET
+ */
+public final class CloseAction extends CallBack {
+
+ private static final String KEY = "OSSCKEY Q";
+ private static final String CLOSE = "Close";
+
+ private SwingScilabVariableEditor editor;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ private CloseAction(SwingScilabVariableEditor editor, String name) {
+ super(name);
+ this.editor = editor;
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(CLOSE, new CloseAction(editor, CLOSE));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), CLOSE);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ EditVar.closeVariableEditor();
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new CloseAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
+}
package org.scilab.modules.ui_data.variableeditor.actions;
-import java.awt.Toolkit;
-import java.awt.datatransfer.StringSelection;
-
-import javax.swing.KeyStroke;
import javax.swing.ImageIcon;
import javax.swing.JTable;
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.gui.pushbutton.ScilabPushButton;
import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
/**
- * RefreshAction class
+ * CopyAction class
* @author Calixte DENIZET
*/
-public final class CopyAction extends CallBack {
+public final class CopyAction extends CopySelectionAction {
- private static final String KEY = "ctrl C";
+ private static final String KEY = "OSSCKEY C";
private static final String COPY = "Copy";
- private SwingScilabVariableEditor editor;
-
/**
* Constructor
* @param editor the editor
* @param name the name of the action
*/
private CopyAction(SwingScilabVariableEditor editor, String name) {
- super(name);
- this.editor = editor;
+ super(editor, name, "", "\n", "\t", "\n");
}
/**
*/
public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
table.getActionMap().put(COPY, new CopyAction(editor, COPY));
- table.getInputMap().put(KeyStroke.getKeyStroke(KEY), COPY);
- }
-
- /**
- * {@inheritDoc}
- */
- public void callBack() {
- JTable table = editor.getCurrentTable();
- int[] cols = table.getSelectedColumns();
- int[] rows = table.getSelectedRows();
- if (cols.length > 0 && rows.length > 0) {
- table.setColumnSelectionInterval(cols[0], cols[cols.length - 1]);
- table.setRowSelectionInterval(rows[0], rows[rows.length - 1]);
- StringBuffer buf = new StringBuffer();
- SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
- for (int i = rows[0]; i <= rows[rows.length - 1]; i++) {
- for (int j = cols[0]; j <= cols[cols.length - 1]; j++) {
- String exp = model.getCellEditor().getExpression(i, j);
- if (exp != null) {
- buf.append("=" + exp);
- } else {
- String val = model.getScilabValueAt(i, j, false);
- if (val != null) {
- buf.append(val);
- }
- }
- if (j < cols[cols.length - 1]) {
- buf.append("\t");
- }
- }
- buf.append("\n");
- }
- StringSelection sel = new StringSelection(buf.toString());
- Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel);
- }
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), COPY);
}
/**
return button;
}
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new CopyAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+
+import javax.swing.JTable;
+
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+
+/**
+ * CopySelectionAction class
+ * @author Calixte DENIZET
+ */
+class CopySelectionAction extends CallBack {
+
+ protected SwingScilabVariableEditor editor;
+ private String begin;
+ private String end;
+ private String colSep;
+ private String rowSep;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ protected CopySelectionAction(SwingScilabVariableEditor editor, String name, String begin, String end, String colSep, String rowSep) {
+ super(name);
+ this.editor = editor;
+ this.begin = begin;
+ this.end = end;
+ this.colSep = colSep;
+ this.rowSep = rowSep;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ JTable table = editor.getCurrentTable();
+ int[] cols = table.getSelectedColumns();
+ int[] rows = table.getSelectedRows();
+ if (cols.length > 0 && rows.length > 0) {
+ StringBuffer buf = new StringBuffer(begin);
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ for (int i = 0; i < rows.length; i++) {
+ for (int j = 0; j < cols.length; j++) {
+ String val = model.getScilabValueAt(rows[i], cols[j], false);
+ if (val != null) {
+ buf.append(val);
+ }
+ if (j < cols.length - 1) {
+ buf.append(colSep);
+ }
+ }
+ if (i < rows.length - 1) {
+ buf.append(rowSep);
+ }
+ }
+ buf.append(end);
+
+ StringSelection sel = new StringSelection(buf.toString());
+ Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+
+import javax.swing.ImageIcon;
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+
+/**
+ * CopySelectionAsScilabCommandAction class
+ * @author Calixte DENIZET
+ */
+public final class CopySelectionAsScilabCommandAction extends CallBack {
+
+ private static final String KEY = "OSSCKEY E";
+ private static final String COPYAS = "Copy as Scilab command";
+
+ private SwingScilabVariableEditor editor;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ private CopySelectionAsScilabCommandAction(SwingScilabVariableEditor editor, String name) {
+ super(name);
+ this.editor = editor;
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(COPYAS, new CopySelectionAsScilabCommandAction(editor, COPYAS));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), COPYAS);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ JTable table = editor.getCurrentTable();
+ int[] cols = table.getSelectedColumns();
+ int[] rows = table.getSelectedRows();
+ if (cols.length > 0 && rows.length > 0) {
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ String command = model.getScilabSubMatrix(rows, cols);
+ StringSelection sel = new StringSelection(command);
+ Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel);
+ }
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new CopySelectionAsScilabCommandAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import javax.swing.ImageIcon;
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+
+/**
+ * CopySelectionAsScilabMatrixAction class
+ * @author Calixte DENIZET
+ */
+public final class CopySelectionAsScilabMatrixAction extends CopySelectionAction {
+
+ private static final String KEY = "OSSCKEY shift E";
+ private static final String COPYAS = "Copy as Scilab matrix";
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ private CopySelectionAsScilabMatrixAction(SwingScilabVariableEditor editor, String name) {
+ super(editor, name, "[", "]", ",", ";");
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(COPYAS, new CopySelectionAsScilabMatrixAction(editor, COPYAS));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), COPYAS);
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new CopySelectionAsScilabMatrixAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import javax.swing.ImageIcon;
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+
+/**
+ * CopySelectionAsScilabMatrixWithCRAction class
+ * @author Calixte DENIZET
+ */
+public final class CopySelectionAsScilabMatrixWithCRAction extends CopySelectionAction {
+
+ private static final String KEY = "OSSCKEY R";
+ private static final String COPYAS = "Copy as Scilab matrix with CR";
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ private CopySelectionAsScilabMatrixWithCRAction(SwingScilabVariableEditor editor, String name) {
+ super(editor, name, "[", "]", ",", ";\n ");
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(COPYAS, new CopySelectionAsScilabMatrixWithCRAction(editor, COPYAS));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), COPYAS);
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new CopySelectionAsScilabMatrixWithCRAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
+}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import java.awt.Dialog.ModalityType;
+import java.awt.GridLayout;
+import java.awt.GridBagLayout;
+import java.awt.GridBagConstraints;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JSpinner;
+import javax.swing.JTextField;
+import javax.swing.KeyStroke;
+import javax.swing.SpinnerNumberModel;
+
+import javax.swing.KeyStroke;
+import javax.swing.ImageIcon;
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.UI_data;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+
+/**
+ * RefreshAction class
+ * @author Calixte DENIZET
+ */
+public final class CreateNewVariableAction extends CallBack {
+
+ private static final String KEY = "OSSCKEY N";
+ private static final String CREATENEW = "Create new";
+ private static final int GAP = 5;
+
+ private SwingScilabVariableEditor editor;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ private CreateNewVariableAction(SwingScilabVariableEditor editor, String name) {
+ super(name);
+ this.editor = editor;
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(CREATENEW, new CreateNewVariableAction(editor, CREATENEW));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), CREATENEW);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ JTable table = editor.getCurrentTable();
+ Object[] values = askForNewMatrix();
+ if (!((String) values[0]).isEmpty()) {
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ String defaultValue = model.getDataAsScilabString(((String) values[3]));
+ if (defaultValue.isEmpty()) {
+ defaultValue = "0";
+ }
+
+ StringBuilder command = new StringBuilder();
+ command.append("L$8625083632641564277=warning(\"query\");warning(\"off\");");
+ command.append("if execstr(\"");
+ command.append((String) values[0]);
+ command.append("=");
+ command.append("repmat(");
+ command.append(defaultValue);
+ command.append(",");
+ command.append(((Integer) values[1]).toString());
+ command.append(",");
+ command.append(((Integer) values[2]).toString());
+ command.append(");editvar(\"\"");
+ command.append((String) values[0]);
+ command.append("\"\")\",\"errcatch\") <> 0 then messagebox(\"Could not create variable: \" + lasterror() + \"\"");
+ command.append(",\"Variable editor\",\"error\",\"modal\");");
+ command.append("end;");
+ command.append("warning(L$8625083632641564277);clear(\"L$8625083632641564277\");");
+ command.append("updatebrowsevar()");
+
+ model.execCommand(command.toString());
+ }
+ }
+
+ public Object[] askForNewMatrix() {
+ final JDialog dialog = new JDialog();
+ final Object[] ret = new Object[]{ "", new Integer(0), new Integer(0), "" };
+ dialog.setModalityType(ModalityType.APPLICATION_MODAL);
+ dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+ dialog.setIconImage(new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/32x32/apps/rrze_table.png").getImage());
+
+ JPanel panel = new JPanel(new GridBagLayout());
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ JLabel label = new JLabel(UiDataMessages.VARNAME);
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.gridwidth = 1;
+ gbc.gridheight = 1;
+ gbc.insets = new Insets(GAP, GAP, 0, GAP);
+ gbc.anchor = GridBagConstraints.WEST;
+ panel.add(label, gbc);
+
+ final JTextField textField = new JTextField(24 + 1);
+ textField.setText(UI_data.getUnnamedVariable());
+ textField.selectAll();
+ gbc.gridx = 1;
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ gbc.insets = new Insets(GAP, 0, 0, GAP);
+ panel.add(textField, gbc);
+
+ JLabel labelRow = new JLabel(UiDataMessages.NUMROWS);
+ gbc.gridx = 0;
+ gbc.gridy = 1;
+ gbc.gridwidth = 1;
+ gbc.gridheight = 1;
+ gbc.fill = GridBagConstraints.NONE;
+ gbc.insets = new Insets(GAP, GAP, 0, GAP);
+ panel.add(labelRow, gbc);
+
+ final JSpinner spinRow = new JSpinner();
+ ((SpinnerNumberModel) spinRow.getModel()).setMinimum(new Comparable<Integer>() {
+ public int compareTo(Integer o) {
+ return -o.intValue();
+ }
+ });
+ spinRow.setValue(0);
+ ((JSpinner.DefaultEditor) spinRow.getEditor()).getTextField().setColumns(6);
+ gbc.gridx = 1;
+ gbc.insets = new Insets(GAP, 0, 0, GAP);
+ panel.add(spinRow, gbc);
+
+ JLabel labelCol = new JLabel(UiDataMessages.NUMCOLS);
+ gbc.gridx = 0;
+ gbc.gridy = 2;
+ gbc.insets = new Insets(GAP, GAP, 0, GAP);
+ panel.add(labelCol, gbc);
+
+ final JSpinner spinCol = new JSpinner();
+ ((SpinnerNumberModel) spinCol.getModel()).setMinimum(new Comparable<Integer>() {
+ public int compareTo(Integer o) {
+ return -o.intValue();
+ }
+ });
+ spinCol.setValue(0);
+ ((JSpinner.DefaultEditor) spinCol.getEditor()).getTextField().setColumns(6);
+ gbc.gridx = 1;
+ gbc.insets = new Insets(GAP, 0, 0, GAP);
+ panel.add(spinCol, gbc);
+
+ JLabel labelFill = new JLabel(UiDataMessages.FILLWITH);
+ gbc.gridx = 0;
+ gbc.gridy = 3;
+ gbc.insets = new Insets(GAP, GAP, 0, GAP);
+ panel.add(labelFill, gbc);
+
+ final JTextField fillField = new JTextField(15);
+ gbc.gridx = 1;
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ gbc.insets = new Insets(GAP, 0, 0, GAP);
+ panel.add(fillField, gbc);
+
+ JButton cancelButton = new JButton(UiDataMessages.CANCEL);
+ JButton okButton = new JButton(UiDataMessages.OK);
+ JPanel panelButton = new JPanel();
+ okButton.setPreferredSize(cancelButton.getPreferredSize());
+ panelButton.setLayout(new GridLayout(1, 2, GAP, GAP));
+ panelButton.setBorder(BorderFactory.createEmptyBorder(GAP, 0, 0, 0));
+ panelButton.add(cancelButton);
+ panelButton.add(okButton);
+
+ gbc.gridx = 1;
+ gbc.gridy = 4;
+ gbc.gridwidth = 1;
+ gbc.weightx = 0;
+ gbc.fill = GridBagConstraints.NONE;
+ gbc.anchor = GridBagConstraints.EAST;
+ panel.add(panelButton, gbc);
+
+ dialog.setContentPane(panel);
+
+ cancelButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ dialog.dispose();
+ }
+ });
+
+ okButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ dialog.dispose();
+ ret[0] = textField.getText();
+ ret[1] = spinRow.getValue();
+ ret[2] = spinCol.getValue();
+ ret[3] = fillField.getText();
+ }
+ });
+
+ dialog.setTitle(UiDataMessages.CREATENEWVAR);
+ dialog.pack();
+ dialog.setResizable(false);
+ dialog.setLocationRelativeTo(editor);
+ dialog.setVisible(true);
+
+ return ret;
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(SwingScilabVariableEditor editor, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new CreateNewVariableAction(editor, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/variable-new.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new CreateNewVariableAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
+}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import java.awt.Dialog.ModalityType;
+import java.awt.GridLayout;
+import java.awt.GridBagLayout;
+import java.awt.GridBagConstraints;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.KeyStroke;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.UI_data;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+
+/**
+ * RefreshAction class
+ * @author Calixte DENIZET
+ */
+public final class CreateVariableFromSelectionAction extends CallBack {
+
+ private static final String KEY = "OSSCKEY K";
+ private static final String CREATE = "Create";
+ private static final int GAP = 5;
+
+ private SwingScilabVariableEditor editor;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ private CreateVariableFromSelectionAction(SwingScilabVariableEditor editor, String name) {
+ super(name);
+ this.editor = editor;
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(CREATE, new CreateVariableFromSelectionAction(editor, CREATE));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), CREATE);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ JTable table = editor.getCurrentTable();
+ int[] cols = table.getSelectedColumns();
+ int[] rows = table.getSelectedRows();
+ if (cols.length > 0 && rows.length > 0) {
+ String varName = askForName();
+ if (!varName.isEmpty()) {
+ int[] rowSize = new int[1];
+ int[] colSize = new int[1];
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ String datas = model.getScilabSubMatrix(rows, cols, rowSize, colSize);
+ model.execCommand(varName + "=" + datas + ";editvar(\"" + varName + "\")");
+ }
+ }
+ }
+
+ public String askForName() {
+ final JDialog dialog = new JDialog();
+ final String[] ret = new String[]{ "" };
+ dialog.setModalityType(ModalityType.APPLICATION_MODAL);
+ dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+ dialog.setIconImage(new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/32x32/apps/rrze_table.png").getImage());
+
+ JPanel panel = new JPanel(new GridBagLayout());
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ JLabel label = new JLabel(UiDataMessages.VARNAME);
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.gridwidth = 1;
+ gbc.gridheight = 1;
+ gbc.insets = new Insets(GAP, GAP, 0, GAP);
+ panel.add(label, gbc);
+
+ final JTextField textField = new JTextField(24 + 1);
+ textField.setText(UI_data.getUnnamedVariable());
+ textField.selectAll();
+ gbc.gridx = 1;
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ panel.add(textField, gbc);
+
+ JButton cancelButton = new JButton(UiDataMessages.CANCEL);
+ JButton okButton = new JButton(UiDataMessages.OK);
+ JPanel panelButton = new JPanel();
+ okButton.setPreferredSize(cancelButton.getPreferredSize());
+ panelButton.setLayout(new GridLayout(1, 2, GAP, GAP));
+ panelButton.setBorder(BorderFactory.createEmptyBorder(GAP, 0, 0, 0));
+ panelButton.add(cancelButton);
+ panelButton.add(okButton);
+
+ gbc.gridx = 1;
+ gbc.gridy = 1;
+ gbc.gridwidth = 1;
+ gbc.weightx = 0;
+ gbc.fill = GridBagConstraints.NONE;
+ gbc.anchor = GridBagConstraints.EAST;
+ gbc.insets = new Insets(GAP, 0, 0, GAP);
+ panel.add(panelButton, gbc);
+
+ dialog.setContentPane(panel);
+
+ cancelButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ dialog.dispose();
+ }
+ });
+
+ okButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ dialog.dispose();
+ ret[0] = textField.getText();
+ }
+ });
+
+ textField.addKeyListener(new KeyAdapter() {
+ public void keyReleased(KeyEvent e) {
+ int code = e.getKeyCode();
+ if (code == KeyEvent.VK_ENTER) {
+ dialog.dispose();
+ ret[0] = textField.getText();
+ } else if (code == KeyEvent.VK_ESCAPE) {
+ dialog.dispose();
+ }
+ }
+ });
+
+ dialog.setTitle(UiDataMessages.CREATEVAR);
+ dialog.pack();
+ dialog.setResizable(false);
+ dialog.setLocationRelativeTo(editor);
+ dialog.setVisible(true);
+
+ return ret[0];
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(SwingScilabVariableEditor editor, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new CreateVariableFromSelectionAction(editor, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/variable-from-selection.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new CreateVariableFromSelectionAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
+}
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
+import java.util.Vector;
import javax.swing.KeyStroke;
import javax.swing.ImageIcon;
import javax.swing.JTable;
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.gui.pushbutton.ScilabPushButton;
import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
*/
public final class CutAction extends CallBack {
- private static final String KEY = "ctrl X";
+ private static final String KEY = "OSSCKEY X";
private static final String CUT = "Cut";
private SwingScilabVariableEditor editor;
*/
public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
table.getActionMap().put(CUT, new CutAction(editor, CUT));
- table.getInputMap().put(KeyStroke.getKeyStroke(KEY), CUT);
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), CUT);
}
/**
table.setColumnSelectionInterval(cols[0], cols[cols.length - 1]);
table.setRowSelectionInterval(rows[0], rows[rows.length - 1]);
StringBuffer buf = new StringBuffer();
+ Object oldValue;
SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ int oldRows = model.getScilabMatrixRowCount();
+ int oldCols = model.getScilabMatrixColCount();
+
+ if (rows[0] >= oldRows || cols[0] >= oldCols) {
+ return;
+ }
+
+ if ((cols.length == 1 && rows.length == 1) || (rows.length >= 2 && cols.length >= 2 && rows[1] >= oldRows && cols[1] >= oldCols)) {
+ oldValue = model.getValueAt(rows[0], cols[0]);
+ } else {
+ oldValue = (Vector) model.cloneDatas();
+ }
+
for (int i = rows[0]; i <= rows[rows.length - 1]; i++) {
for (int j = cols[0]; j <= cols[cols.length - 1]; j++) {
- String exp = model.getCellEditor().getExpression(i, j);
- if (exp != null) {
- buf.append("=" + exp);
- } else {
- String val = model.getScilabValueAt(i, j, false);
- if (val != null) {
- buf.append(val);
- }
+ String val = model.getScilabValueAt(i, j, false);
+ if (val != null) {
+ buf.append(val);
}
model.emptyValueAt(i, j);
if (j < cols[cols.length - 1]) {
model.removeRow(i, cols[0], cols[cols.length - 1]);
}
for (int j = cols[cols.length - 1]; j >= cols[0]; j--) {
- model.removeCol(table, j, rows[0], rows[rows.length - 1]);
+ model.removeCol(j, rows[0], rows[rows.length - 1]);
+ }
+
+ if (oldValue instanceof Vector) {
+ model.updateFullMatrix(oldValue, oldRows, oldCols);
+ } else {
+ model.updateMatrix(oldValue, rows[0], cols[0]);
}
- model.updateMatrix();
- StringSelection sel = new StringSelection(buf.toString());
+
+ StringSelection sel = new StringSelection(buf.toString());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel);
}
}
return button;
}
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new CutAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import java.awt.Dialog.ModalityType;
+import java.awt.GridLayout;
+import java.awt.GridBagLayout;
+import java.awt.GridBagConstraints;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.ui_data.UI_data;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+
+/**
+ * RefreshAction class
+ * @author Calixte DENIZET
+ */
+public final class DuplicateVariableAction extends CallBack {
+
+ private static final String KEY = "OSSCKEY D";
+ private static final String CREATE = "Duplicate";
+ private static final int GAP = 5;
+
+ private SwingScilabVariableEditor editor;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ private DuplicateVariableAction(SwingScilabVariableEditor editor, String name) {
+ super(name);
+ this.editor = editor;
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(CREATE, new DuplicateVariableAction(editor, CREATE));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), CREATE);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ JTable table = editor.getCurrentTable();
+ String varName = askForName();
+ if (!varName.isEmpty()) {
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ model.execCommand(varName + "=" + model.getVarName() + ";editvar(\"" + varName + "\")");
+ }
+ }
+
+ public String askForName() {
+ final JDialog dialog = new JDialog();
+ final String[] ret = new String[]{ "" };
+ dialog.setModalityType(ModalityType.APPLICATION_MODAL);
+ dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+ dialog.setIconImage(new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/32x32/apps/rrze_table.png").getImage());
+
+ JPanel panel = new JPanel(new GridBagLayout());
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ JLabel label = new JLabel(UiDataMessages.VARNAME);
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.gridwidth = 1;
+ gbc.gridheight = 1;
+ gbc.insets = new Insets(GAP, GAP, 0, GAP);
+ panel.add(label, gbc);
+
+ final JTextField textField = new JTextField(24 + 1);
+ textField.setText(UI_data.getUnnamedVariable());
+ textField.selectAll();
+ gbc.gridx = 1;
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ panel.add(textField, gbc);
+
+ JButton cancelButton = new JButton(UiDataMessages.CANCEL);
+ JButton okButton = new JButton(UiDataMessages.OK);
+ JPanel panelButton = new JPanel();
+ okButton.setPreferredSize(cancelButton.getPreferredSize());
+ panelButton.setLayout(new GridLayout(1, 2, GAP, GAP));
+ panelButton.setBorder(BorderFactory.createEmptyBorder(GAP, 0, 0, 0));
+ panelButton.add(cancelButton);
+ panelButton.add(okButton);
+
+ gbc.gridx = 1;
+ gbc.gridy = 1;
+ gbc.gridwidth = 1;
+ gbc.weightx = 0;
+ gbc.fill = GridBagConstraints.NONE;
+ gbc.anchor = GridBagConstraints.EAST;
+ gbc.insets = new Insets(GAP, 0, 0, GAP);
+ panel.add(panelButton, gbc);
+
+ dialog.setContentPane(panel);
+
+ cancelButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ dialog.dispose();
+ }
+ });
+
+ okButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ dialog.dispose();
+ ret[0] = textField.getText();
+ }
+ });
+
+ textField.addKeyListener(new KeyAdapter() {
+ public void keyReleased(KeyEvent e) {
+ int code = e.getKeyCode();
+ if (code == KeyEvent.VK_ENTER) {
+ dialog.dispose();
+ ret[0] = textField.getText();
+ } else if (code == KeyEvent.VK_ESCAPE) {
+ dialog.dispose();
+ }
+ }
+ });
+
+ dialog.setTitle(UiDataMessages.CREATEVAR);
+ dialog.pack();
+ dialog.setResizable(false);
+ dialog.setLocationRelativeTo(editor);
+ dialog.setVisible(true);
+
+ return ret[0];
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new DuplicateVariableAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JTable;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.TableVariableEditor;
+
+/**
+ * Set Precision Action class
+ * @author Calixte DENIZET
+ */
+public final class InsertColumnAction extends CallBack {
+
+ private JTable table;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ public InsertColumnAction(JTable table, String name) {
+ super(name);
+ this.table = table;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ int[] rows = table.getSelectedRows();
+ int column = ((TableVariableEditor) table).getPopupColumn();
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ model.insertColumn(column);
+ table.setColumnSelectionInterval(column, column);
+ for (int i = 0; i < rows.length; i++) {
+ table.addRowSelectionInterval(rows[i], rows[i]);
+ }
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(JTable table, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new InsertColumnAction(table, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/short.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static JMenuItem createMenuItem(JTable table, String title) {
+ JMenuItem mi = new JMenuItem(title);
+ mi.addActionListener(new InsertColumnAction(table, title));
+
+ return mi;
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JTable;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.TableVariableEditor;
+
+/**
+ * Set Precision Action class
+ * @author Calixte DENIZET
+ */
+public final class InsertRowAction extends CallBack {
+
+ private JTable table;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ public InsertRowAction(JTable table, String name) {
+ super(name);
+ this.table = table;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ int row = ((TableVariableEditor) table).getPopupRow();
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ model.insertRow(row);
+ table.setRowSelectionInterval(row, row);
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(JTable table, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new InsertRowAction(table, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/short.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static JMenuItem createMenuItem(JTable table, String title) {
+ JMenuItem mi = new JMenuItem(title);
+ mi.addActionListener(new InsertRowAction(table, title));
+
+ return mi;
+ }
+}
package org.scilab.modules.ui_data.variableeditor.actions;
+import java.awt.Cursor;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.StringTokenizer;
+import java.util.Vector;
import javax.swing.KeyStroke;
import javax.swing.ImageIcon;
import javax.swing.JTable;
+import javax.swing.event.TableModelEvent;
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.gui.pushbutton.ScilabPushButton;
import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
*/
public final class PasteAction extends CallBack {
- private static final String KEY = "ctrl V";
+ private static final String KEY = "OSSCKEY V";
private static final String PASTE = "Paste";
private SwingScilabVariableEditor editor;
*/
public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
table.getActionMap().put(PASTE, new PasteAction(editor, PASTE));
- table.getInputMap().put(KeyStroke.getKeyStroke(KEY), PASTE);
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), PASTE);
}
/**
table.setColumnSelectionInterval(col, col);
table.setRowSelectionInterval(row, row);
String str = "";
+ editor.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
str = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this).getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException ex1) {
System.err.println(ex2);
}
StringTokenizer rElems = new StringTokenizer(str, "\n");
- SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
- for (int i = 0; rElems.hasMoreTokens(); i++) {
+ int countRows = rElems.countTokens();
+ Vector vr = new Vector(countRows);
+ for (int i = 0; i < countRows; i++) {
StringTokenizer cElems = new StringTokenizer(rElems.nextToken(), "\t");
- for (int j = 0; cElems.hasMoreTokens(); j++) {
- String value = (String) cElems.nextToken();
- model.setValueAtAndUpdate(false, value, row + i, col + j);
+ int countCols = cElems.countTokens();
+ Vector vc = new Vector(countCols);
+ for (int j = 0; j < countCols; j++) {
+ vc.addElement(cElems.nextToken());
}
+ vr.addElement(vc);
+ }
+
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ int oldRows = model.getScilabMatrixRowCount();
+ int oldCols = model.getScilabMatrixColCount();
+
+ if (vr.size() == 1 && ((Vector) vr.get(0)).size() == 1 && row < oldRows && col < oldCols) {
+ model.setValueAtAndUpdate(true, true, ((Vector) vr.get(0)).get(0), row, col);
+ } else {
+ Vector oldVector = (Vector) model.cloneDatas();
+ model.setValues(vr, row, col);
+ model.updateFullMatrix(oldVector, oldRows, oldCols);
}
- model.updateMatrix();
}
/**
return button;
}
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new PasteAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import java.awt.Component;
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.KeyStroke;
+import javax.swing.ImageIcon;
+import javax.swing.JPopupMenu;
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.EditVar;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+
+/**
+ * RefreshAction class
+ * @author Calixte DENIZET
+ */
+public final class PlotAction extends CallBack {
+
+ public static final int PLOT2D = 0;
+ public static final int MATPLOT = 1;
+ public static final int GRAYPLOT = 2;
+ public static final int SGRAYPLOT = 3;
+ public static final int CHAMP = 4;
+ public static final int HISTPLOT = 5;
+ public static final int MESH = 6;
+ public static final int SURF = 7;
+ public static final int HIST3D = 8;
+ public static final int CONTOUR2D = 9;
+ public static final int PIE = 10;
+
+ private static final Map<String, Integer> map = new HashMap<String, Integer>();
+ static {
+ map.put("plot2d", 0);
+ map.put("Matplot", 1);
+ map.put("grayplot", 2);
+ map.put("Sgrayplot", 3);
+ map.put("champ", 4);
+ map.put("histplot", 5);
+ map.put("mesh", 6);
+ map.put("surf", 7);
+ map.put("hist3d", 8);
+ map.put("contour2d", 9);
+ map.put("pie", 10);
+ }
+
+ private static final String COM_PLOT2D = "plot2d(%s)";
+ private static final String COM_MATPLOT = "Matplot(%s)";
+ private static final String COM_GRAYPLOT = "grayplot(1:%s,1:%s,%s)";
+ private static final String COM_SGRAYPLOT = "Sgrayplot(1:%s,1:%s,%s)";
+ private static final String COM_CHAMP = "champ(1:%s,1:%s,real(%s),imag(%s))";
+ private static final String COM_HISTPLOT = "histplot(10,%s)";
+ private static final String COM_MESH = "mesh(%s)";
+ private static final String COM_SURF = "surf(%s)";
+ private static final String COM_HIST3D = "hist3d(%s)";
+ private static final String COM_CONTOUR2D = "L?8625083632641564278=xget(\"fpf\");xset(\"fpf\",\" \");contour2d(1:%s,1:%s,%s,10);xset(\"fpf\",L?8625083632641564278);clear(\"L?8625083632641564278\")";
+ private static final String COM_PIE = "L?8625083632641564278=%s;pie(L?8625083632641564278(find(L?8625083632641564278>0&L?8625083632641564278<>%%inf&L?8625083632641564278<>%%nan)))";
+
+ private static final String PATHTOIMG = System.getenv("SCI") + "/modules/gui/images/icons/64x64/";
+
+ private static final String[] COMMANDS = new String[]{COM_PLOT2D, COM_MATPLOT, COM_GRAYPLOT, COM_SGRAYPLOT, COM_CHAMP, COM_HISTPLOT, COM_MESH, COM_SURF, COM_HIST3D, COM_CONTOUR2D, COM_PIE};
+ private static final String[] IMG = new String[]{"plot2d.png", "Matplot.png", "grayplot.png", "Sgrayplot.png", "champ.png", "histplot.png", "mesh.png", "surf.png", "hist3d.png", "contour2d.png", "pie.png"};
+
+ private static final String CREATE = "Create";
+
+ private SwingScilabVariableEditor editor;
+ private int type;
+ private boolean onSelection;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ private PlotAction(SwingScilabVariableEditor editor, String name, boolean onSelection) {
+ super(name);
+ this.editor = editor;
+ this.type = map.get(name);
+ this.onSelection = onSelection;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ JTable table = editor.getCurrentTable();
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ String datas = null;
+ int rowC = 0;
+ int colC = 0;
+
+ if (!onSelection) {
+ rowC = model.getScilabMatrixRowCount();
+ colC = model.getScilabMatrixColCount();
+ datas = model.getVarName();
+ } else {
+ int[] cols = table.getSelectedColumns();
+ int[] rows = table.getSelectedRows();
+ if (cols.length > 0 && rows.length > 0) {
+ if (model.getType().equals(EditVar.STRING)) {
+ return;
+ }
+
+ int[] rowSize = new int[1];
+ int[] colSize = new int[1];
+ datas = model.getScilabSubMatrix(rows, cols, rowSize, colSize);
+ if (datas == null) {
+ return;
+ }
+ rowC = rowSize[0];
+ colC = colSize[0];
+ }
+ }
+
+ if (!model.getType().equals(EditVar.DOUBLE)) {
+ datas = "double(" + datas + ")";
+ }
+
+ String com = COMMANDS[type];
+ switch (type) {
+ case 0:
+ case 1:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 10:
+ com = String.format(com, datas);
+ break;
+ case 2:
+ case 3:
+ com = String.format(com, rowC, colC, datas);
+ break;
+ case 4:
+ com = String.format(com, rowC, colC, datas, datas);
+ break;
+ case 9:
+ if (rowC >= 2 && colC >= 2) {
+ com = String.format(com, rowC, colC, datas);
+ } else {
+ return;
+ }
+ break;
+ }
+
+ model.execCommand("clf();" + com);
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(SwingScilabVariableEditor editor, String title) {
+ final PushButton button = ScilabPushButton.createPushButton();
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/plot.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ final JPopupMenu popup = new JPopupMenu() {
+ public void show(Component c, int x, int y) {
+ SwingScilabPushButton but = (SwingScilabPushButton) button.getAsSimplePushButton();
+ super.show(but, 0, but.getBounds(null).height);
+ }
+ };
+ popup.setBorderPainted(true);
+
+ popup.add(PlotAction.createJMenuItem(editor, "plot2d", true));
+ popup.add(PlotAction.createJMenuItem(editor, "Matplot", true));
+ popup.add(PlotAction.createJMenuItem(editor, "grayplot", true));
+ popup.add(PlotAction.createJMenuItem(editor, "Sgrayplot", true));
+ popup.add(PlotAction.createJMenuItem(editor, "champ", true));
+ popup.add(PlotAction.createJMenuItem(editor, "histplot", true));
+ popup.add(PlotAction.createJMenuItem(editor, "mesh", true));
+ popup.add(PlotAction.createJMenuItem(editor, "surf", true));
+ popup.add(PlotAction.createJMenuItem(editor, "hist3d", true));
+ popup.add(PlotAction.createJMenuItem(editor, "contour2d", true));
+ popup.add(PlotAction.createJMenuItem(editor, "pie", true));
+
+ popup.pack();
+
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new CallBack(null) {
+ public void callBack() {
+ if (!popup.isVisible()) {
+ popup.show(null, 0, 0);
+ } else {
+ popup.setVisible(false);
+ }
+ }
+ });
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title, boolean onSelection) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new PlotAction(editor, title, onSelection));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setIcon(new ImageIcon(PATHTOIMG + IMG[map.get(title)]));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title, boolean onSelection) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title, onSelection).getAsSimpleMenuItem();
+ }
+}
package org.scilab.modules.ui_data.variableeditor.actions;
-import javax.swing.KeyStroke;
import javax.swing.ImageIcon;
import javax.swing.JTable;
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.gui.pushbutton.ScilabPushButton;
import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
*/
public final class RedoAction extends CallBack {
- private static final String KEY = "ctrl Y";
+ private static final String KEY = "OSSCKEY Y";
private static final String REDO = "Redo";
private SwingScilabVariableEditor editor;
*/
public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
table.getActionMap().put(REDO, new RedoAction(editor, REDO));
- table.getInputMap().put(KeyStroke.getKeyStroke(KEY), REDO);
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), REDO);
}
/**
return button;
}
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new RedoAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JTable;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.TableVariableEditor;
+
+/**
+ * Set Precision Action class
+ * @author Calixte DENIZET
+ */
+public final class RemoveColumnAction extends CallBack {
+
+ private JTable table;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ public RemoveColumnAction(JTable table, String name) {
+ super(name);
+ this.table = table;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ int[] cols = table.getSelectedColumns();
+ if (cols.length == 0) {
+ cols = new int[]{((TableVariableEditor) table).getPopupColumn()};
+ }
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ model.removeColumns(cols);
+ table.clearSelection();
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(JTable table, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new RemoveColumnAction(table, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/short.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static JMenuItem createMenuItem(JTable table, String title) {
+ JMenuItem mi = new JMenuItem(title);
+ mi.addActionListener(new RemoveColumnAction(table, title));
+
+ return mi;
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JTable;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.TableVariableEditor;
+
+/**
+ * Set Precision Action class
+ * @author Calixte DENIZET
+ */
+public final class RemoveRowAction extends CallBack {
+
+ private JTable table;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ public RemoveRowAction(JTable table, String name) {
+ super(name);
+ this.table = table;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ int[] rows = table.getSelectedRows();
+ if (rows.length == 0) {
+ rows = new int[]{((TableVariableEditor) table).getPopupRow()};
+ }
+ SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ model.removeRows(rows);
+ table.clearSelection();
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(JTable table, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new RemoveRowAction(table, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/short.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static JMenuItem createMenuItem(JTable table, String title) {
+ JMenuItem mi = new JMenuItem(title);
+ mi.addActionListener(new RemoveRowAction(table, title));
+
+ return mi;
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+import java.util.Vector;
+
+import javax.swing.KeyStroke;
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+import org.scilab.modules.ui_data.variableeditor.renderers.ScilabComplexRenderer;
+
+/**
+ * Set Precision Action class
+ * @author Calixte DENIZET
+ */
+public final class SetPrecisionLongAction extends CallBack {
+
+ private static final String KEY = "OSSCKEY L";
+ private static final String PRECISION = "Long Precision";
+
+ private SwingScilabVariableEditor editor;
+
+ protected int precision;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ public SetPrecisionLongAction(SwingScilabVariableEditor editor, String name) {
+ super(name);
+ this.editor = editor;
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(PRECISION, new SetPrecisionLongAction(editor, PRECISION));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), PRECISION);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ ScilabComplexRenderer.setFormat(ScilabComplexRenderer.LONG);
+ editor.getCurrentTable().repaint();
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(SwingScilabVariableEditor editor, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new SetPrecisionLongAction(editor, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/long.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static JMenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ JMenuItem mi = new JMenuItem(title);
+ mi.addActionListener(new SetPrecisionLongAction(editor, title));
+ mi.setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return mi;
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+import java.util.Vector;
+
+import javax.swing.KeyStroke;
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+import org.scilab.modules.ui_data.variableeditor.renderers.ScilabComplexRenderer;
+
+/**
+ * Set Precision Action class
+ * @author Calixte DENIZET
+ */
+public final class SetPrecisionLongeAction extends CallBack {
+
+ private static final String KEY = "OSSCKEY shift L";
+ private static final String PRECISION = "Long E Precision";
+
+ private SwingScilabVariableEditor editor;
+
+ protected int precision;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ public SetPrecisionLongeAction(SwingScilabVariableEditor editor, String name) {
+ super(name);
+ this.editor = editor;
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(PRECISION, new SetPrecisionLongeAction(editor, PRECISION));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), PRECISION);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ ScilabComplexRenderer.setFormat(ScilabComplexRenderer.LONGE);
+ editor.getCurrentTable().repaint();
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(SwingScilabVariableEditor editor, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new SetPrecisionLongeAction(editor, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/longe.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static JMenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ JMenuItem mi = new JMenuItem(title);
+ mi.addActionListener(new SetPrecisionLongeAction(editor, title));
+ mi.setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return mi;
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+import java.util.Vector;
+
+import javax.swing.KeyStroke;
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+import org.scilab.modules.ui_data.variableeditor.renderers.ScilabComplexRenderer;
+
+/**
+ * Set Precision Action class
+ * @author Calixte DENIZET
+ */
+public final class SetPrecisionShortAction extends CallBack {
+
+ private static final String KEY = "OSSCKEY S";
+ private static final String PRECISION = "Short Precision";
+
+ private SwingScilabVariableEditor editor;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ public SetPrecisionShortAction(SwingScilabVariableEditor editor, String name) {
+ super(name);
+ this.editor = editor;
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(PRECISION, new SetPrecisionShortAction(editor, PRECISION));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), PRECISION);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ ScilabComplexRenderer.setFormat(ScilabComplexRenderer.SHORT);
+ editor.getCurrentTable().repaint();
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(SwingScilabVariableEditor editor, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new SetPrecisionShortAction(editor, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/short.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static JMenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ JMenuItem mi = new JMenuItem(title);
+ mi.addActionListener(new SetPrecisionShortAction(editor, title));
+ mi.setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return mi;
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+import java.util.Vector;
+
+import javax.swing.KeyStroke;
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+import org.scilab.modules.ui_data.variableeditor.renderers.ScilabComplexRenderer;
+
+/**
+ * Set Precision Action class
+ * @author Calixte DENIZET
+ */
+public final class SetPrecisionShorteAction extends CallBack {
+
+ private static final String KEY = "OSSCKEY shift S";
+ private static final String PRECISION = "Short E Precision";
+
+ private SwingScilabVariableEditor editor;
+
+ protected int precision;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ public SetPrecisionShorteAction(SwingScilabVariableEditor editor, String name) {
+ super(name);
+ this.editor = editor;
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(PRECISION, new SetPrecisionShorteAction(editor, PRECISION));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), PRECISION);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ ScilabComplexRenderer.setFormat(ScilabComplexRenderer.SHORTE);
+ editor.getCurrentTable().repaint();
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(SwingScilabVariableEditor editor, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new SetPrecisionShorteAction(editor, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/shorte.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static JMenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ JMenuItem mi = new JMenuItem(title);
+ mi.addActionListener(new SetPrecisionShorteAction(editor, title));
+ mi.setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return mi;
+ }
+}
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.actions;
+
+import javax.swing.ImageIcon;
+import javax.swing.JTable;
+
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
+import org.scilab.modules.ui_data.variableeditor.TableVariableEditor;
+
+/**
+ * RefreshAction class
+ * @author Calixte DENIZET
+ */
+public final class SizeColumnsToFitAction extends CallBack {
+
+ private static final String KEY = "OSSCKEY F";
+ private static final String FIT = "Size to fit";
+
+ private SwingScilabVariableEditor editor;
+
+ /**
+ * Constructor
+ * @param editor the editor
+ * @param name the name of the action
+ */
+ public SizeColumnsToFitAction(SwingScilabVariableEditor editor, String name) {
+ super(name);
+ this.editor = editor;
+ }
+
+ /**
+ * @param editor the editor
+ * @param table where to put the action
+ */
+ public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
+ table.getActionMap().put(FIT, new SizeColumnsToFitAction(editor, FIT));
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), FIT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void callBack() {
+ TableVariableEditor table = (TableVariableEditor) editor.getCurrentTable();
+ table.sizeColumnsToFit();
+ }
+
+ /**
+ * Create a button for a tool bar
+ * @param editor the associated editor
+ * @param title tooltip for the button
+ * @return the button
+ */
+ public static PushButton createButton(SwingScilabVariableEditor editor, String title) {
+ PushButton button = ScilabPushButton.createPushButton();
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new SizeColumnsToFitAction(editor, title));
+ button.setToolTipText(title);
+ ImageIcon imageIcon = new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/16x16/actions/SizeColumnsToFit.png");
+ ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);
+
+ return button;
+ }
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new SizeColumnsToFitAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
+}
package org.scilab.modules.ui_data.variableeditor.actions;
+import java.util.Vector;
+
import javax.swing.KeyStroke;
import javax.swing.JTable;
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
import org.scilab.modules.ui_data.variableeditor.SwingScilabVariableEditor;
int[] cols = table.getSelectedColumns();
int[] rows = table.getSelectedRows();
if (cols.length > 0 && rows.length > 0) {
+ Object oldValue;
SwingEditvarTableModel model = (SwingEditvarTableModel) table.getModel();
+ int oldRows = model.getScilabMatrixRowCount();
+ int oldCols = model.getScilabMatrixColCount();
+
+ if (rows[0] >= oldRows || cols[0] >= oldCols) {
+ return;
+ }
+
+ if ((cols.length == 1 && rows.length == 1) || (rows.length >= 2 && cols.length >= 2 && rows[1] >= oldRows && cols[1] >= oldCols)) {
+ oldValue = model.getValueAt(rows[0], cols[0]);
+ } else {
+ oldValue = (Vector) model.cloneDatas();
+ }
table.setColumnSelectionInterval(cols[0], cols[cols.length - 1]);
table.setRowSelectionInterval(rows[0], rows[rows.length - 1]);
for (int i = rows[rows.length - 1]; i >= rows[0]; i--) {
for (int j = cols[cols.length - 1]; j >= cols[0]; j--) {
- model.getCellEditor().removeExpression(i, j);
model.emptyValueAt(i, j);
}
model.removeRow(i, cols[0], cols[cols.length - 1]);
}
for (int j = cols[cols.length - 1]; j >= cols[0]; j--) {
- model.removeCol(table, j, rows[0], rows[rows.length - 1]);
+ model.removeCol(j, rows[0], rows[rows.length - 1]);
+ }
+
+ if (oldValue instanceof Vector) {
+ model.updateFullMatrix(oldValue, oldRows, oldCols);
+ } else {
+ model.updateMatrix(oldValue, rows[0], cols[0]);
}
- model.updateMatrix();
}
}
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new SupprAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(KeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
}
import javax.swing.ImageIcon;
import javax.swing.JTable;
+import org.scilab.modules.commons.gui.ScilabKeyStroke;
+
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.gui.pushbutton.ScilabPushButton;
import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
*/
public final class UndoAction extends CallBack {
- private static final String KEY = "ctrl Z";
+ private static final String KEY = "OSSCKEY Z";
private static final String UNDO = "Undo";
private SwingScilabVariableEditor editor;
*/
public static void registerAction(SwingScilabVariableEditor editor, JTable table) {
table.getActionMap().put(UNDO, new UndoAction(editor, UNDO));
- table.getInputMap().put(KeyStroke.getKeyStroke(KEY), UNDO);
+ table.getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), UNDO);
}
/**
return button;
}
+
+ /**
+ * Create a menu item
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static MenuItem createMenuItem(SwingScilabVariableEditor editor, String title) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setCallback(new UndoAction(editor, title));
+ menu.setText(title);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(ScilabKeyStroke.getKeyStroke(KEY));
+
+ return menu;
+ }
+
+ /**
+ * Create a menu item as a SwingScilabMenuItem
+ * @param editor the associated editor
+ * @param title the menu title
+ * @return the menu item
+ */
+ public static SwingScilabMenuItem createJMenuItem(SwingScilabVariableEditor editor, String title) {
+ return (SwingScilabMenuItem) createMenuItem(editor, title).getAsSimpleMenuItem();
+ }
}
editor = new ScilabBooleanCellEditor();
} else if (type.equals(EditVar.INTEGER)) {
editor = new ScilabIntegerCellEditor();
+ } else if (type.equals(EditVar.SPARSE)) {
+ editor = new ScilabDoubleCellEditor();
+ } else if (type.equals(EditVar.COMPLEXSPARSE)) {
+ editor = new ScilabComplexCellEditor();
+ } else if (type.equals(EditVar.BOOLEANSPARSE)) {
+ editor = new ScilabBooleanCellEditor();
}
return editor;
package org.scilab.modules.ui_data.variableeditor.celleditor;
import java.awt.Component;
-import java.util.Map;
-import java.util.WeakHashMap;
-import java.util.Iterator;
+import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JFormattedTextField;
import javax.swing.JTable;
private static final long serialVersionUID = -5713675180587317165L;
- private Map<Coords, String> expressions = new WeakHashMap();
-
/**
* Constructor
*/
public ScilabGenericCellEditor() {
super(new JFormattedTextField());
+ ((JFormattedTextField) getComponent()).setBorder(BorderFactory.createEmptyBorder());
}
/**
* {@inheritDoc}
*/
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) {
- String exp = getExpression(row, col);
- if (exp == null) {
- return super.getTableCellEditorComponent(table, getDataAsScilabString(value), isSelected, row, col);
- } else {
- return super.getTableCellEditorComponent(table, "=" + exp, isSelected, row, col);
- }
- }
-
- /**
- * @param map the expressions
- */
- public void setExpressions(Map<Coords, String> map) {
- expressions = map;
- }
-
- /**
- * @return the expressions
- */
- public Map<Coords, String> getExpressions() {
- return expressions;
- }
-
- /**
- * @param exp the expression
- * @param row the row
- * @param col the col
- */
- public void addExpression(String exp, int row, int col) {
- expressions.put(new Coords(row, col), exp);
- }
-
- /**
- * @param row the row
- * @param col the col
- * @return the expression
- */
- public String getExpression(int row, int col) {
- return expressions.get(new Coords(row, col));
- }
-
- /**
- * @param row the row
- * @param col the col
- */
- public void removeExpression(int row, int col) {
- expressions.remove(new Coords(row, col));
- }
-
- /**
- * @param var the variable name
- * @return all the expressions in one scilab expression
- */
- public String getAllExpressions(String var) {
- String exp = "";
- Iterator<Coords> iter = expressions.keySet().iterator();
- while (iter.hasNext()) {
- Coords c = iter.next();
- exp += var + "(" + (c.x + 1) + "," + (c.y + 1) + ")=" + expressions.get(c) + ";";
- }
-
- return exp;
- }
-
- /**
- * Inner class to handle the coords (row, col)
- */
- private class Coords {
- protected int x;
- protected int y;
- private int hashcode;
-
- /**
- * Constructor
- * @param x the row
- * @param y the col
- */
- Coords(int x, int y) {
- this.x = x;
- this.y = y;
- /* this formula is an explicit bijection between NxN and N. */
- this.hashcode = x + (x + y) * (x + y + 1) / 2;
- }
-
- /**
- * {@inheritDoc}
- */
- public int hashCode() {
- return hashcode;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean equals(Object o) {
- return (o instanceof Coords) && ((Coords) o).x == x && ((Coords) o).y == y;
- }
+ return super.getTableCellEditorComponent(table, getDataAsScilabString(value), isSelected, row, col);
}
}
renderer = new ScilabBooleanRenderer();
} else if (type.equals(EditVar.INTEGER)) {
renderer = new ScilabIntegerRenderer();
+ } else if (type.equals(EditVar.SPARSE)) {
+ renderer = new ScilabSparseRenderer();
+ } else if (type.equals(EditVar.COMPLEXSPARSE)) {
+ renderer = new ScilabComplexSparseRenderer();
+ } else if (type.equals(EditVar.BOOLEANSPARSE)) {
+ renderer = new ScilabBooleanSparseRenderer();
}
return renderer;
--- /dev/null
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variableeditor.renderers;
+
+import java.awt.Color;
+import java.awt.Component;
+
+import javax.swing.JTable;
+
+import org.scilab.modules.ui_data.datatable.SwingEditvarTableModel;
+
+/**
+ * CellRenderer for boolean type
+ * @author Calixte DENIZET
+ */
+public class ScilabBooleanSparseRenderer extends ScilabBooleanRenderer {
+
+ /**
+ * Constructor
+ */
+ public ScilabBooleanSparseRenderer() {
+ super();
+ }
+
+ protected static boolean isNothing(Object value) {
+ return value == null || (value instanceof Boolean && !((Boolean) value).booleanValue());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void setValue(Object value) {
+ if (isNothing(value)) {
+ super.setValue(null);
+ } else {
+ super.setValue(value);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+ if (isNothing(value) && !isSelected && ((SwingEditvarTableModel) table.getModel()).getScilabMatrixRowCount() > row && ((SwingEditvarTableModel) table.getModel()).getScilabMatrixColCount() > column) {
+ setBackground(Color.LIGHT_GRAY);
+ } else {
+ setBackground(null);