<path value="$SCILAB/modules/graphic_export/.libs"/>
<path value="$SCILAB/modules/scinotes/.libs"/>
<path value="$SCILAB/modules/commons/.libs"/>
+<path value="$SCILAB/modules/gui/.libs"/>
<path value="$SCILAB/.libs"/>
<!-- Default path to the JNI classes under some Linux (JoGL under Debian for example) -->
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.commons.gui;
+
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowFocusListener;
+
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+
+/**
+ * GUI utilities
+ * @author Calixte DENIZET
+ */
+public class ScilabGUIUtilities {
+
+ /**
+ * Bring a window to the front
+ * @param window the window to bring to the front
+ */
+ public static void toFront(final JFrame window) {
+ WindowFocusListener listener = new WindowFocusListener() {
+
+ public void windowGainedFocus(WindowEvent e) {
+ window.setAlwaysOnTop(true);
+ }
+
+ public void windowLostFocus(WindowEvent e) {
+ window.setAlwaysOnTop(false);
+ window.removeWindowFocusListener(this);
+ }
+ };
+ window.addWindowFocusListener(listener);
+ window.toFront();
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ window.requestFocus();
+ }
+ });
+ }
+}
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
}
/**
+ * Retrieve the list of the elements which have an attribute equals to the given value.
+ * @param root the root element
+ * @param attribute the attribute name
+ * @param value the value
+ * @return the list
+ */
+ public static List<Element> getElementsWithAttributeEquals(Element root, String attribute, String value) {
+ List<Element> list = new ArrayList<Element>();
+ getElementsWithAttributeEquals(root, attribute, value, list);
+
+ return list;
+ }
+
+ /**
+ * Retrieve the list of the elements which have an attribute equals to the given value (recursive function).
+ * @param root the root element
+ * @param attribute the attribute name
+ * @param value the value
+ * @param list the list to fill
+ */
+ private static final void getElementsWithAttributeEquals(Element root, String attribute, String value, List<Element> list) {
+ if (root.getAttribute(attribute).equals(value)) {
+ list.add(root);
+ }
+ if (root.hasChildNodes()) {
+ NodeList nodes = root.getChildNodes();
+ int length = nodes.getLength();
+ for (int i = 0; i < length; i++) {
+ Node node = nodes.item(i);
+ if (node instanceof Element) {
+ Element elem = (Element) nodes.item(i);
+ getElementsWithAttributeEquals(elem, attribute, value, list);
+ }
+ }
+ }
+ }
+
+ /**
* Convert a value (as String) into an object according to its class type giving in clazz
* @param value the value to convert
* @param clazz the class type of the value
caret.setBlinkRate(getCaret().getBlinkRate());
setCaret(caret);
addCaretListener(this);
+ setFocusTraversalPolicy(new java.awt.DefaultFocusTraversalPolicy() {
+ public java.awt.Component getComponentAfter(java.awt.Container aContainer, java.awt.Component aComponent) {
+ return SciInputCommandView.this;
+ }
+ });
+ setFocusCycleRoot(true);
}
/**
CHECK_SRC= $(CORE_C_SOURCES) $(GATEWAY_C_SOURCES)
INCLUDE_FLAGS = $(libscicore_la_CFLAGS)
-libscicore_algo_la_SOURCES = $(CORE_C_SOURCES) $(CORE_CPP_SOURCES) $(CORE_FORTRAN_SOURCES) $(JNI_SOURCES)
+libscicore_algo_la_SOURCES = $(CORE_C_SOURCES) $(CORE_CPP_SOURCES) $(CORE_FORTRAN_SOURCES)
libscicore_la_SOURCES = $(GATEWAY_C_SOURCES) $(GATEWAY_FORTRAN_SOURCES)
libscicore_algo_la_CFLAGS = $(libscicore_la_CFLAGS)
libscicore_algo_la_CPPFLAGS = $(libscicore_la_CPPFLAGS)
sci_gateway/fortran/sci_f_comp.f \
sci_gateway/fortran/sci_f_isglobal.f
-libscicore_la_CFLAGS = -I$(srcdir)/includes/ -I$(srcdir)/src/c/ \
+libscicore_la_CFLAGS = $(JAVA_JNI_INCLUDE) -I$(srcdir)/includes/ \
+ -I$(srcdir)/src/c/ -I$(srcdir)/src/jni/ \
-I$(top_srcdir)/libs/MALLOC/includes/ \
-I$(top_srcdir)/libs/dynamiclibrary/includes/ \
-I$(top_srcdir)/libs/doublylinkedlist/includes \
-I$(top_srcdir)/modules/fileio/includes \
-I$(top_srcdir)/modules/shell/includes $(XML_FLAGS) \
$(am__append_3)
-libscicore_la_CPPFLAGS = -I$(srcdir)/includes/ \
+libscicore_la_CPPFLAGS = $(JAVA_JNI_INCLUDE) \
+ -I$(srcdir)/includes/ \
-I$(srcdir)/src/c/ \
+ -I$(srcdir)/src/jni/ \
-I$(srcdir)/src/cpp/ \
-I$(top_srcdir)/modules/dynamic_link/includes \
-I$(top_srcdir)/libs/MALLOC/includes/
# For the code check (splint)
CHECK_SRC = $(CORE_C_SOURCES) $(GATEWAY_C_SOURCES)
INCLUDE_FLAGS = $(libscicore_la_CFLAGS)
-libscicore_algo_la_SOURCES = $(CORE_C_SOURCES) $(CORE_CPP_SOURCES) $(CORE_FORTRAN_SOURCES) $(JNI_SOURCES)
+libscicore_algo_la_SOURCES = $(CORE_C_SOURCES) $(CORE_CPP_SOURCES) $(CORE_FORTRAN_SOURCES)
libscicore_la_SOURCES = $(GATEWAY_C_SOURCES) $(GATEWAY_FORTRAN_SOURCES)
libscicore_algo_la_CFLAGS = $(libscicore_la_CFLAGS)
libscicore_algo_la_CPPFLAGS = $(libscicore_la_CPPFLAGS)
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2009 - DIGITEO - Allan CORNET
- *
+ *
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
- * are also available at
+ * are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
*
*/
#include "localization.h"
#include "Scierror.h"
#include "exitCodeValue.h"
+#include "../../../jvm/src/c/createMainScilabObject.h"
/*--------------------------------------------------------------------------*/
int C2F(sci_exit)(char *fname,unsigned long fname_len)
{
- SciErr sciErr;
+ SciErr sciErr;
+ double *pdVarOne = NULL;
- CheckLhs(1,1);
- CheckRhs(0,1);
+ CheckLhs(1,1);
+ CheckRhs(0,1);
- if (Rhs == 0)
- {
- setExitCodeValue(0);
- }
- else
- {
- int iExit = 0;
- int m1 = 0, n1 = 0;
- int iType1 = 0;
- int *piAddressVarOne = NULL;
- double *pdVarOne = NULL;
+ if (Rhs == 0)
+ {
+ setExitCodeValue(0);
+ }
+ else
+ {
+ int iExit = 0;
+ int m1 = 0, n1 = 0;
+ int iType1 = 0;
+ int *piAddressVarOne = NULL;
- /* get Address of inputs */
- sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
- if(sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
- }
+ /* get Address of inputs */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
- sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1);
- if(sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
- }
+ sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
- /* check input type */
- if ( iType1 != sci_matrix )
- {
- Scierror(999,_("%s: Wrong type for input argument #%d: A scalar expected.\n"),fname,1);
- return 0;
- }
+ /* check input type */
+ if ( iType1 != sci_matrix )
+ {
+ Scierror(999,_("%s: Wrong type for input argument #%d: A scalar expected.\n"),fname,1);
+ return 0;
+ }
- sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne,&m1,&n1,&pdVarOne);
- if(sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
- }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne,&m1,&n1,&pdVarOne);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
- if( n1 != 1 || m1 != 1)
- {
- Scierror(999,_("%s: Wrong size for input argument #%d: A scalar expected.\n"),fname,1);
- return 0;
- }
+ if( n1 != 1 || m1 != 1)
+ {
+ Scierror(999,_("%s: Wrong size for input argument #%d: A scalar expected.\n"),fname,1);
+ return 0;
+ }
- iExit = (int) *pdVarOne;
+ iExit = (int) *pdVarOne;
- if (*pdVarOne != (double)iExit)
- {
- Scierror(999,_("%s: Wrong value for input argument #%d: An integer expected.\n"),fname,1);
- return 0;
- }
+ if (*pdVarOne != (double)iExit)
+ {
+ Scierror(999,_("%s: Wrong value for input argument #%d: An integer expected.\n"),fname,1);
+ return 0;
+ }
- setExitCodeValue(iExit);
- }
+ setExitCodeValue(iExit);
+ }
- // this value do quit in scirun
- C2F(com).fun = -999;
+ if (pdVarOne || canCloseMainScilabObject())
+ {
+ // this value do quit in scirun
+ C2F(com).fun = -999;
+ }
- LhsVar(1) = 0;
- C2F(putlhsvar)();
+ LhsVar(1) = 0;
+ C2F(putlhsvar)();
- return 0;
+ return 0;
}
/*--------------------------------------------------------------------------*/
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2007 - INRIA - Allan CORNET
- *
+ *
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
- * are also available at
+ * are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
*
*/
#include "getvariablesname.h"
#include "stackinfo.h"
#include "MALLOC.h"
-/*--------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/
static void SortStrings(char **Strings,int SizeStrings);
static void RemoveDuplicateStrings(char **Strings,int *SizeStrings);
-/*--------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/
char **getVariablesName(int *sizearray, BOOL sorted)
{
- char **variables = NULL;
+ char **variables = NULL;
- char **localvariables = NULL;
- int sizelocalvariables = 0;
+ char **localvariables = NULL;
+ int sizelocalvariables = 0;
- char **globalvariables = NULL;
- int sizeglobalvariables = 0;
+ char **globalvariables = NULL;
+ int sizeglobalvariables = 0;
- localvariables = getLocalVariablesName(&sizelocalvariables,sorted);
- globalvariables = getGlobalVariablesName(&sizeglobalvariables,sorted);
+ localvariables = getLocalVariablesName(&sizelocalvariables,sorted);
+ globalvariables = getGlobalVariablesName(&sizeglobalvariables,sorted);
- if (localvariables && globalvariables)
- {
- int i = 0;
- variables = (char **)MALLOC(sizeof(char*)*(sizelocalvariables+sizeglobalvariables+1));
- for (i = 0; i < sizelocalvariables ; i++) variables[i] = localvariables[i];
- for (i = sizelocalvariables; i < sizelocalvariables + sizeglobalvariables; i++)
- {
- variables[i] = globalvariables[i - sizelocalvariables];
- }
- FREE(localvariables); localvariables = NULL;
- FREE(globalvariables); globalvariables = NULL;
- }
+ if (localvariables || globalvariables)
+ {
+ int i = 0;
+ variables = (char **)MALLOC(sizeof(char*)*(sizelocalvariables+sizeglobalvariables+1));
+ for (i = 0; i < sizelocalvariables ; i++) variables[i] = localvariables[i];
+ for (i = sizelocalvariables; i < sizelocalvariables + sizeglobalvariables; i++)
+ {
+ variables[i] = globalvariables[i - sizelocalvariables];
+ }
+ if (localvariables)
+ {
+ FREE(localvariables);
+ localvariables = NULL;
+ }
+ if (globalvariables)
+ {
+ FREE(globalvariables);
+ globalvariables = NULL;
+ }
+ }
- if (variables)
- {
- *sizearray = sizelocalvariables+sizeglobalvariables;
- if (sorted) SortStrings(variables,*sizearray);
- RemoveDuplicateStrings(variables,sizearray);
- }
- else
- {
- *sizearray = 0;
- }
- return variables;
+ if (variables)
+ {
+ *sizearray = sizelocalvariables+sizeglobalvariables;
+ if (sorted) SortStrings(variables,*sizearray);
+ RemoveDuplicateStrings(variables,sizearray);
+ }
+ else
+ {
+ *sizearray = 0;
+ }
+ return variables;
}
-/*----------------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------------*/
char **getLocalVariablesName(int *sizearray,BOOL sorted)
{
- char **variablesLocal = NULL;
- int Ltotal = 0;
- int Lused = 0;
- int j = 0;
+ char **variablesLocal = NULL;
+ int Ltotal = 0;
+ int Lused = 0;
+ int j = 0;
- C2F(getvariablesinfo)(&Ltotal,&Lused);
+ C2F(getvariablesinfo)(&Ltotal,&Lused);
- if (Lused)
- {
- variablesLocal = (char **)MALLOC(sizeof(char*)*(Lused+1));
- if (variablesLocal)
- {
- for (j=1;j<Lused+1;++j) variablesLocal[j-1] = getLocalNamefromId(j);
- *sizearray = Lused;
- if (sorted) SortStrings(variablesLocal,*sizearray);
- }
- else
- {
- *sizearray = 0;
- }
- }
- else
- {
- *sizearray = 0;
- }
+ if (Lused > 0)
+ {
+ variablesLocal = (char **)MALLOC(sizeof(char*)*(Lused+1));
+ if (variablesLocal)
+ {
+ for (j=1;j<Lused+1;++j) variablesLocal[j-1] = getLocalNamefromId(j);
+ *sizearray = Lused;
+ if (sorted) SortStrings(variablesLocal,*sizearray);
+ }
+ else
+ {
+ *sizearray = 0;
+ }
+ }
+ else
+ {
+ *sizearray = 0;
+ }
- return variablesLocal;
+ return variablesLocal;
}
-/*--------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/
char **getGlobalVariablesName(int *sizearray, BOOL sorted)
{
- char **variablesGlobal = NULL;
- int Gtotal = 0;
- int Gused = 0;
- int j = 0;
+ char **variablesGlobal = NULL;
+ int Gtotal = 0;
+ int Gused = 0;
+ int j = 0;
- C2F(getgvariablesinfo)(&Gtotal,&Gused);
+ C2F(getgvariablesinfo)(&Gtotal,&Gused);
- if (Gused)
- {
- variablesGlobal = (char **)MALLOC(sizeof(char*)*(Gused+1));
- if (variablesGlobal)
- {
- for (j=0;j<Gused;++j) variablesGlobal[j] = getGlobalNamefromId(j);
- *sizearray = Gused;
- if (sorted) SortStrings(variablesGlobal,*sizearray);
- }
- else
- {
- *sizearray = 0;
- }
- }
- else
- {
- *sizearray = 0;
- }
+ if (Gused > 0)
+ {
+ variablesGlobal = (char **)MALLOC(sizeof(char*)*(Gused+1));
+ if (variablesGlobal)
+ {
+ for (j=0;j<Gused;++j) variablesGlobal[j] = getGlobalNamefromId(j);
+ *sizearray = Gused;
+ if (sorted) SortStrings(variablesGlobal,*sizearray);
+ }
+ else
+ {
+ *sizearray = 0;
+ }
+ }
+ else
+ {
+ *sizearray = 0;
+ }
- return variablesGlobal;
+ return variablesGlobal;
}
-/*--------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/
static void SortStrings(char **Strings,int SizeStrings)
{
- int fin,i;
- for(fin=SizeStrings-1;fin>0;fin--)
- {
- int Sorted=FALSE;
- for(i=0;i<fin;i++)
- {
- if(strcmp(Strings[i],Strings[i+1])>0)
- {
- char *StringTmp;
+ int fin,i;
+ for(fin=SizeStrings-1;fin>0;fin--)
+ {
+ int Sorted=FALSE;
+ for(i=0;i<fin;i++)
+ {
+ if(strcmp(Strings[i],Strings[i+1])>0)
+ {
+ char *StringTmp;
- StringTmp = Strings[i];
+ StringTmp = Strings[i];
- Strings[i] = Strings[i+1];
- Strings[i+1] = StringTmp;
+ Strings[i] = Strings[i+1];
+ Strings[i+1] = StringTmp;
- Sorted=TRUE;
- }
- }
- if(!Sorted)break;
- }
+ Sorted=TRUE;
+ }
+ }
+ if(!Sorted)break;
+ }
}
-/*--------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/
static void RemoveDuplicateStrings(char **Strings,int *SizeStrings)
{
- int fin,i;
- int newsize = *SizeStrings;
- for(fin=*SizeStrings-1;fin>0;fin--)
- {
- int Sorted=FALSE;
- for(i=0;i<fin;i++)
- {
- if (Strings[i])
- {
- if(strcmp(Strings[i],Strings[i+1]) == 0)
- {
- FREE(Strings[i+1]);
- Strings[i+1] = NULL;
- Sorted=TRUE;
- newsize--;
- }
- }
- else
- {
- Strings[i] = Strings[i+1];
- Strings[i+1] = NULL;
- Sorted=TRUE;
- }
- }
- if(!Sorted)break;
- }
+ int fin,i;
+ int newsize = *SizeStrings;
+ for(fin=*SizeStrings-1;fin>0;fin--)
+ {
+ int Sorted=FALSE;
+ for(i=0;i<fin;i++)
+ {
+ if (Strings[i])
+ {
+ if(strcmp(Strings[i],Strings[i+1]) == 0)
+ {
+ FREE(Strings[i+1]);
+ Strings[i+1] = NULL;
+ Sorted=TRUE;
+ newsize--;
+ }
+ }
+ else
+ {
+ Strings[i] = Strings[i+1];
+ Strings[i+1] = NULL;
+ Sorted=TRUE;
+ }
+ }
+ if(!Sorted)break;
+ }
- *SizeStrings = newsize;
+ *SizeStrings = newsize;
}
-/*--------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/
{
dynamic_TerminateTclTk();
TerminateGraphics();
- TerminateGUI();
TerminateJVM();
}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - 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.core;
+
+import java.awt.event.ActionEvent;
+import java.util.List;
+import java.util.UUID;
+
+import javax.swing.JTextArea;
+
+import org.scilab.modules.jvm.LoadClassPath;
+import org.scilab.modules.gui.ScilabTermination;
+import org.scilab.modules.gui.bridge.CallScilabBridge;
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.console.ScilabConsole;
+import org.scilab.modules.gui.events.callback.CallBack;
+import org.scilab.modules.gui.menubar.MenuBar;
+import org.scilab.modules.gui.tab.ScilabTab;
+import org.scilab.modules.gui.tab.Tab;
+import org.scilab.modules.gui.textbox.ScilabTextBox;
+import org.scilab.modules.gui.textbox.TextBox;
+import org.scilab.modules.gui.toolbar.ToolBar;
+import org.scilab.modules.gui.utils.ClosingOperationsManager;
+import org.scilab.modules.gui.utils.ConfigManager;
+import org.scilab.modules.gui.utils.MenuBarBuilder;
+import org.scilab.modules.gui.utils.ToolBarBuilder;
+import org.scilab.modules.gui.utils.UIElementMapper;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
+import org.scilab.modules.gui.window.Window;
+import org.scilab.modules.localization.Messages;
+
+/**
+ *
+ * @author Calixte DENIZET
+ */
+public class ConsoleTab {
+
+ private static final String CLASS_NOT_FOUND = "Could not find class: ";
+ private static final String SEE_DEFAULT_PATHS = "See SCI/etc/classpath.xml for default paths.";
+ private static final String SCIDIR = System.getenv("SCI");
+ private static final String MENUBARXMLFILE = SCIDIR + "/modules/gui/etc/main_menubar.xml";
+ private static final String TOOLBARXMLFILE = SCIDIR + "/modules/gui/etc/main_toolbar.xml";
+ private static final String NOCONSOLE = Messages.gettext("No available console !\nPlease use STD mode.");
+ private static final String EMPTYTAB = Messages.gettext("Empty tab");
+
+ /**
+ * Create a console tab
+ * @param uuid the console uuid
+ * @return the corresponding tab
+ */
+ public static Tab getConsoleTab(String uuid) {
+ if (Scilab.getMode() != 2) {
+ Tab tab = ScilabTab.createTab(EMPTYTAB, uuid);
+ JTextArea textarea = new JTextArea(NOCONSOLE);
+ textarea.setEditable(false);
+ ((SwingScilabTab) tab.getAsSimpleTab()).setContentPane(textarea);
+
+ ClosingOperationsManager.registerClosingOperation(tab, new ClosingOperationsManager.ClosingOperation() {
+
+ public boolean canClose() {
+ return true;
+ }
+
+ public void destroy() { }
+
+ public String askForClosing() {
+ return null;
+ }
+ });
+
+ ClosingOperationsManager.addDependencyWithRoot(tab);
+
+ return tab;
+ }
+
+ MenuBar menuBar = MenuBarBuilder.buildMenuBar(MENUBARXMLFILE);
+ ToolBar toolBar = ToolBarBuilder.buildToolBar(TOOLBARXMLFILE);
+
+ /* Create the console */
+ Tab consoleTab = null;
+ try {
+ /* CONSOLE */
+ /* Create a tab to put console into */
+ LoadClassPath.loadOnUse("Console");
+ if (uuid == null) {
+ consoleTab = ScilabTab.createTab(Messages.gettext("Scilab Console"), UUID.randomUUID().toString());
+ } else {
+ consoleTab = ScilabTab.createTab(Messages.gettext("Scilab Console"), uuid);
+ }
+
+ ClosingOperationsManager.registerClosingOperation(consoleTab, new ClosingOperationsManager.ClosingOperation() {
+
+ public boolean canClose() {
+ CallScilabBridge.unblockConsole();
+
+ return true;
+ }
+
+ public void destroy() {
+ ScilabTermination.ScilabExit();
+ }
+
+ public String askForClosing() {
+ return "Console";
+ }
+ });
+
+ ClosingOperationsManager.setRoot(consoleTab);
+
+ ScilabConsole.createConsole();
+ } catch (NoClassDefFoundError exception) {
+ System.err.println("Cannot create Scilab Console.\nCheck if the thirdparties are available (JoGL/JRosetta...).\n"
+ + SEE_DEFAULT_PATHS);
+ System.err.println(CLASS_NOT_FOUND + exception.getLocalizedMessage());
+ System.exit(-1);
+ }
+
+ TextBox infoBar = ScilabTextBox.createTextBox();
+
+ /** Adding content into container */
+ toolBar.setVisible(false); // Enabled in scilab.start
+ ScilabConsole.getConsole().addToolBar(toolBar);
+ ScilabConsole.getConsole().addMenuBar(menuBar);
+ ScilabConsole.getConsole().addInfoBar(infoBar);
+ ScilabConsole.getConsole().setMaxOutputSize(ConfigManager.getMaxOutputSize());
+ consoleTab.addMember(ScilabConsole.getConsole());
+
+ return consoleTab;
+ }
+}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - 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.core;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.scilab.modules.gui.tab.Tab;
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.tabfactory.AbstractScilabTabFactory;
+import org.scilab.modules.gui.tabfactory.ScilabTabFactory;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
+
+/**
+ * The main Tab factory.
+ * A component which needs to restore a Tab with a given uuid must register its factory.
+ *
+ * @author Calixte DENIZET
+ */
+public class ConsoleTabFactory extends AbstractScilabTabFactory {
+
+ public static final String APPLICATION = "Console";
+ public static final String PACKAGE = "Console";
+ public static final String CLASS = "org.scilab.modules.core.ConsoleTabFactory";
+ public static final String NULLUUID = new UUID(0L, 0L).toString();
+
+ private static ConsoleTabFactory instance;
+
+ /**
+ * Default constructor
+ */
+ public ConsoleTabFactory() { }
+
+ public SwingScilabTab getTab(String uuid) {
+ if (isAValidUUID(uuid)) {
+ return (SwingScilabTab) ConsoleTab.getConsoleTab(uuid).getAsSimpleTab();
+ }
+ return null;
+ }
+
+ public String getPackage() {
+ return PACKAGE;
+ }
+
+ public String getClassName() {
+ return CLASS;
+ }
+
+ public String getApplication() {
+ return APPLICATION;
+ }
+
+ public boolean isAValidUUID(String uuid) {
+ return uuid.equals(NULLUUID);
+ }
+
+ /**
+ * @return an instance of this factory
+ */
+ public static ConsoleTabFactory getInstance() {
+ if (instance == null) {
+ instance = new ConsoleTabFactory();
+ }
+
+ return instance;
+ }
+}
* Copyright (C) 2007-2008 - INRIA - Sylvestre LEDRU
* Copyright (C) 2007-2008 - INRIA - Jean-Baptiste SILVY
* Copyright (C) 2007-2008 - INRIA - Bruno JOFRET
+ * Copyright (C) 2011 - Calixte DENIZET
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
package org.scilab.modules.core;
+import java.lang.reflect.InvocationTargetException;
+
import javax.swing.JPopupMenu;
+import javax.swing.SwingUtilities;
import org.flexdock.docking.DockingConstants;
+import org.flexdock.docking.DockingManager;
import org.scilab.modules.commons.ScilabConstants;
import org.scilab.modules.jvm.LoadClassPath;
+import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
import org.scilab.modules.gui.console.ScilabConsole;
-import org.scilab.modules.gui.events.callback.CallBack;
-import org.scilab.modules.gui.menubar.MenuBar;
-import org.scilab.modules.gui.tab.ScilabTab;
-import org.scilab.modules.gui.tab.Tab;
-import org.scilab.modules.gui.textbox.ScilabTextBox;
-import org.scilab.modules.gui.textbox.TextBox;
-import org.scilab.modules.gui.toolbar.ToolBar;
+import org.scilab.modules.gui.tabfactory.ScilabTabFactory;
+import org.scilab.modules.gui.utils.ClosingOperationsManager;
import org.scilab.modules.gui.utils.ConfigManager;
import org.scilab.modules.gui.utils.LookAndFeelManager;
-import org.scilab.modules.gui.utils.MenuBarBuilder;
-import org.scilab.modules.gui.utils.ToolBarBuilder;
-import org.scilab.modules.gui.window.ScilabWindow;
+import org.scilab.modules.gui.utils.UIElementMapper;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
import org.scilab.modules.gui.window.Window;
-import org.scilab.modules.localization.Messages;
import java.io.File;
import java.io.IOException;
* @author Vincent COUVERT
* @author Sylvestre Ledru
* @author Bruno JOFRET
+ * @author Calixte DENIZET
*/
public class Scilab {
private static String SCIDIR;
- private static String MENUBARXMLFILE;
-
- private static String TOOLBARXMLFILE;
+ private static boolean success;
+ private static boolean finish;
+ private static int mode;
- private static List<Runnable> hooks = new ArrayList<Runnable>();
+ private static List<Runnable> finalhooks = new ArrayList<Runnable>();
+ private static List<Runnable> initialhooks = new ArrayList<Runnable>();
private Window mainView;
-
/**
* Constructor Scilab Class.
* @param mode Mode Scilab -NW -NWNI -STD -API
*/
public Scilab(int mode) {
+ this.mode = mode;
+ DockingManager.setDockableFactory(ScilabTabFactory.getInstance());
+
/*
* Set Scilab directory. Note that it is done in the constructor
* and not as directly when setting the member because we had some
System.exit(-1);
}
- MENUBARXMLFILE = SCIDIR + "/modules/gui/etc/main_menubar.xml";
- TOOLBARXMLFILE = SCIDIR + "/modules/gui/etc/main_toolbar.xml";
-
/*
* Set options for JOGL
* they must be set before creating GUI
}
if (mode == 2) { /* Mode GUI */
-
// Create a user config file if not already exists
ConfigManager.createUserCopy();
- try {
- mainView = ScilabWindow.createWindow();
- } catch (NoClassDefFoundError exception) {
- System.err.println("Cannot create Scilab Window.\n"
- + "Check if the thirdparties are available (Flexdock, JOGL...).\n" + SEE_DEFAULT_PATHS);
- System.err.println(CLASS_NOT_FOUND + exception.getLocalizedMessage());
- System.exit(-1);
- } catch (java.awt.HeadlessException exception) {
- System.err.println("Error during the initialization of the window: " + exception.getLocalizedMessage());
- System.exit(-1);
- }
-
- mainView.setPosition(ConfigManager.getMainWindowPosition());
- mainView.setDims(ConfigManager.getMainWindowSize());
+ WindowsConfigurationManager.restoreUUID(ConsoleTabFactory.NULLUUID);
- /************/
- /* MENU BAR */
- /************/
- MenuBar menuBar = MenuBarBuilder.buildMenuBar(MENUBARXMLFILE);
-
- /************/
- /* TOOL BAR */
- /************/
- ToolBar toolBar = ToolBarBuilder.buildToolBar(TOOLBARXMLFILE);
-
- /* Create the console */
- Tab consoleTab = null;
- try {
- /* CONSOLE */
- /* Create a tab to put console into */
- LoadClassPath.loadOnUse("Console");
- consoleTab = ScilabTab.createTab(Messages.gettext("Scilab Console"));
- /* Exit Scilab when the console is closed */
- consoleTab.setCallback(CallBack.createCallback("exit();", CallBack.SCILAB_INSTRUCTION));
-
- ScilabConsole.createConsole();
- } catch (NoClassDefFoundError exception) {
- System.err.println("Cannot create Scilab Console.\nCheck if the thirdparties are available (JoGL/JRosetta...).\n"
- + SEE_DEFAULT_PATHS);
- System.err.println(CLASS_NOT_FOUND + exception.getLocalizedMessage());
- System.exit(-1);
- }
-
- TextBox infoBar = ScilabTextBox.createTextBox();
-
- /** Adding content into container */
- toolBar.setVisible(false); // Enabled in scilab.start
- ScilabConsole.getConsole().addToolBar(toolBar);
- ScilabConsole.getConsole().addMenuBar(menuBar);
- ScilabConsole.getConsole().addInfoBar(infoBar);
- ScilabConsole.getConsole().setMaxOutputSize(ConfigManager.getMaxOutputSize());
- consoleTab.addMember(ScilabConsole.getConsole());
- mainView.addTab(consoleTab);
- mainView.draw();
+ SwingScilabConsole sciConsole = ((SwingScilabConsole) ScilabConsole.getConsole().getAsSimpleConsole());
+ SwingScilabTab consoleTab = (SwingScilabTab) sciConsole.getParent();
+ mainView = (Window) UIElementMapper.getCorrespondingUIElement(consoleTab.getParentWindowId());
}
}
/**
+ * @return the current mode
+ */
+ public static int getMode() {
+ return mode;
+ }
+
+ /**
* Sets the prompt displayed in Scilab console
* @param prompt the prompt to be displayed as a String
*/
}
/**
+ * Call from canCloseMainScilabObject (call itself from sci_exit)
+ * @return true if the console is closed
+ */
+ public static boolean canClose() {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ success = ClosingOperationsManager.startClosingOperationOnRoot();
+ finish = true;
+ }
+ });
+
+ while (!finish) {
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ System.err.println(e);
+ }
+ }
+
+ finish = false;
+
+ return success;
+ }
+
+ /**
* Register a hook to execute just before the JVM shutdown.
* A hook should not contain threads, there is no warranty that they will be fully executed.
*/
- public static void registerHook(Runnable hook) {
- hooks.add(hook);
+ public static void registerFinalHook(Runnable hook) {
+ finalhooks.add(hook);
}
/**
* Remove a hook
*/
- public static void removeHook(Runnable hook) {
- hooks.remove(hook);
+ public static void removeFinalHook(Runnable hook) {
+ finalhooks.remove(hook);
}
/**
* This method should be called from jni (finishMainScilabObject())
*/
public static void executeFinalHooks() {
- for (Runnable hook : hooks) {
+ for (Runnable hook : finalhooks) {
hook.run();
}
}
+
+ /**
+ * Register a hook to execute after the Scilab initialization.
+ * A hook should not contain threads, there is no warranty that they will be fully executed.
+ */
+ public static void registerInitialHook(Runnable hook) {
+ initialhooks.add(hook);
+ }
+
+ /**
+ * Remove a hook
+ */
+ public static void removeInitialHook(Runnable hook) {
+ initialhooks.remove(hook);
+ }
+
+ /**
+ * This method should be called from C (realmain)
+ */
+ public static void executeInitialHooks() {
+ for (final Runnable hook : initialhooks) {
+ try {
+ SwingUtilities.invokeAndWait(hook);
+ } catch (InterruptedException e) {
+ System.err.println(e);
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+ }
}
/*--------------------------------------------------------------------------*/
src/c/CreateUIContextMenu.c \
src/c/UicontrolStyleToString.c \
src/c/checkColorRange.c \
-src/c/messageboxoptions.c
+src/c/messageboxoptions.c \
+src/c/ScilabTermination.c \
+src/jni/ScilabTermination_wrap.c
GUI_CPP_SOURCES = src/cpp/InitUIMenu.cpp \
src/jni/CallScilabBridge.cpp \
src/cpp/displaytree.cpp \
src/jni/ScilabDisplayTree.cpp
-
GIWS_WRAPPERS = \
src/jni/CallScilabBridge.giws.xml \
src/jni/Jxclick.giws.xml \
endif
+#### SWIG Declaration ####
+SWIG_WRAPPERS = src/jni/ScilabTermination.i
+
+if SWIG
+ BUILT_SOURCES=swig
+endif
+
+
GATEWAY_C_SOURCES = sci_gateway/c/sci_x_choice.c \
sci_gateway/c/gw_gui.c \
sci_gateway/c/sci_x_mdialog.c \
libscigui_algo_la-CreateUIContextMenu.lo \
libscigui_algo_la-UicontrolStyleToString.lo \
libscigui_algo_la-checkColorRange.lo \
- libscigui_algo_la-messageboxoptions.lo
+ libscigui_algo_la-messageboxoptions.lo \
+ libscigui_algo_la-ScilabTermination.lo \
+ libscigui_algo_la-ScilabTermination_wrap.lo
am__objects_2 = libscigui_algo_la-InitUIMenu.lo \
libscigui_algo_la-CallScilabBridge.lo \
libscigui_algo_la-Jxclick.lo \
src/c/CreateUIContextMenu.c \
src/c/UicontrolStyleToString.c \
src/c/checkColorRange.c \
-src/c/messageboxoptions.c
+src/c/messageboxoptions.c \
+src/c/ScilabTermination.c \
+src/jni/ScilabTermination_wrap.c
GUI_CPP_SOURCES = src/cpp/InitUIMenu.cpp \
src/jni/CallScilabBridge.cpp \
src/jni/ScilabDisplayTree.giws.xml
@GIWS_TRUE@BUILT_SOURCES = giws
+@SWIG_TRUE@BUILT_SOURCES = swig
+
+#### SWIG Declaration ####
+SWIG_WRAPPERS = src/jni/ScilabTermination.i
GATEWAY_C_SOURCES = sci_gateway/c/sci_x_choice.c \
sci_gateway/c/gw_gui.c \
sci_gateway/c/sci_x_mdialog.c \
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_algo_la-PushButton.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_algo_la-RadioButton.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_algo_la-ScilabDisplayTree.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_algo_la-ScilabTermination.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_algo_la-ScilabTermination_wrap.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_algo_la-SetUicontrolBackgroundColor.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_algo_la-SetUicontrolFontAngle.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigui_algo_la-SetUicontrolFontName.Plo@am__quote@
@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) $(libscigui_algo_la_CPPFLAGS) $(CPPFLAGS) $(libscigui_algo_la_CFLAGS) $(CFLAGS) -c -o libscigui_algo_la-messageboxoptions.lo `test -f 'src/c/messageboxoptions.c' || echo '$(srcdir)/'`src/c/messageboxoptions.c
+libscigui_algo_la-ScilabTermination.lo: src/c/ScilabTermination.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscigui_algo_la_CPPFLAGS) $(CPPFLAGS) $(libscigui_algo_la_CFLAGS) $(CFLAGS) -MT libscigui_algo_la-ScilabTermination.lo -MD -MP -MF $(DEPDIR)/libscigui_algo_la-ScilabTermination.Tpo -c -o libscigui_algo_la-ScilabTermination.lo `test -f 'src/c/ScilabTermination.c' || echo '$(srcdir)/'`src/c/ScilabTermination.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libscigui_algo_la-ScilabTermination.Tpo $(DEPDIR)/libscigui_algo_la-ScilabTermination.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/c/ScilabTermination.c' object='libscigui_algo_la-ScilabTermination.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) $(libscigui_algo_la_CPPFLAGS) $(CPPFLAGS) $(libscigui_algo_la_CFLAGS) $(CFLAGS) -c -o libscigui_algo_la-ScilabTermination.lo `test -f 'src/c/ScilabTermination.c' || echo '$(srcdir)/'`src/c/ScilabTermination.c
+
+libscigui_algo_la-ScilabTermination_wrap.lo: src/jni/ScilabTermination_wrap.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscigui_algo_la_CPPFLAGS) $(CPPFLAGS) $(libscigui_algo_la_CFLAGS) $(CFLAGS) -MT libscigui_algo_la-ScilabTermination_wrap.lo -MD -MP -MF $(DEPDIR)/libscigui_algo_la-ScilabTermination_wrap.Tpo -c -o libscigui_algo_la-ScilabTermination_wrap.lo `test -f 'src/jni/ScilabTermination_wrap.c' || echo '$(srcdir)/'`src/jni/ScilabTermination_wrap.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libscigui_algo_la-ScilabTermination_wrap.Tpo $(DEPDIR)/libscigui_algo_la-ScilabTermination_wrap.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/jni/ScilabTermination_wrap.c' object='libscigui_algo_la-ScilabTermination_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) $(libscigui_algo_la_CPPFLAGS) $(CPPFLAGS) $(libscigui_algo_la_CFLAGS) $(CFLAGS) -c -o libscigui_algo_la-ScilabTermination_wrap.lo `test -f 'src/jni/ScilabTermination_wrap.c' || echo '$(srcdir)/'`src/jni/ScilabTermination_wrap.c
+
libscigui_disable_la-nogui.lo: src/nogui/nogui.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscigui_disable_la_CFLAGS) $(CFLAGS) -MT libscigui_disable_la-nogui.lo -MD -MP -MF $(DEPDIR)/libscigui_disable_la-nogui.Tpo -c -o libscigui_disable_la-nogui.lo `test -f 'src/nogui/nogui.c' || echo '$(srcdir)/'`src/nogui/nogui.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libscigui_disable_la-nogui.Tpo $(DEPDIR)/libscigui_disable_la-nogui.Plo
--- /dev/null
+<?xml version="1.0"?>
+<Scilab>
+ <Window height="453" uuid="5171ff0a-e5e6-4ea9-8525-8d9a5434b881" width="556" x="180" y="25">
+ <DockingPortNode>
+ <DockableNode dockableId="00000000-0000-0000-0000-000000000000"/>
+ </DockingPortNode>
+ </Window>
+ <Console factory="org.scilab.modules.core.ConsoleTabFactory" load="Console" uuid="00000000-0000-0000-0000-000000000000" winuuid="5171ff0a-e5e6-4ea9-8525-8d9a5434b881"/>
+</Scilab>
\ No newline at end of file
</submenu>
<separator/>
<submenu label="&Command History">
- <callback instruction='org.scilab.modules.history_browser.CommandHistory.toggleVisibility' type="3"/>
+ <callback instruction='org.scilab.modules.history_browser.CommandHistory.setVisible' type="3"/>
</submenu>
</menu>
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - 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 "sciquit.h"
+#include "exitCodeValue.h"
+/*--------------------------------------------------------------------------*/
+void ScilabExit(void)
+{
+ setExitCodeValue(0);
+ sciquit();
+ exit(0);
+}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - 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 __SCILABTERMINATION_H__
+#define __SCILABTERMINATION_H__
+
+/**
+* Exit Scilab from Java
+**/
+void ScilabExit(void);
+
+#endif /* __SCILABTERMINATION_H__ */
+/*--------------------------------------------------------------------------*/
--- /dev/null
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.40
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.scilab.modules.gui;
+
+
+ /**
+ * @author Calixte DENIZET
+ */
+public class ScilabTermination {
+
+ /**
+ * Constructor
+ */
+ protected ScilabTermination() {
+ throw new UnsupportedOperationException();
+ }
+ public static void ScilabExit() {
+ ScilabTerminationJNI.ScilabExit();
+ }
+
+}
--- /dev/null
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.40
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.scilab.modules.gui;
+
+
+/* It is generated code. Disable checkstyle */
+//CHECKSTYLE:OFF
+ /**
+ * @author Calixte DENIZET
+ */
+public class ScilabTerminationJNI {
+
+ /**
+ * Constructor
+ */
+ protected ScilabTerminationJNI() {
+ throw new UnsupportedOperationException();
+ }
+
+ static {
+ try {
+ System.loadLibrary("scigui");
+ } 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) {
+ if (System.getenv("CONTINUE_ON_JNI_ERROR") == null) {
+ System.err.println("The native library core does not exist or cannot be found.");
+ System.err.println(e.getLocalizedMessage());
+ e.printStackTrace(System.err);
+ }
+ }
+ }
+
+ public final static native void ScilabExit();
+}
import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
import org.scilab.modules.gui.bridge.helpbrowser.SwingScilabHelpBrowser;
import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
import org.scilab.modules.gui.canvas.Canvas;
import org.scilab.modules.gui.checkbox.CheckBox;
import org.scilab.modules.gui.checkbox.ScilabCheckBox;
import org.scilab.modules.renderer.FigureMapper;
import org.scilab.modules.renderer.figureDrawing.DrawableFigureGL;
-
/**
* This class is used to call Scilab GUIs objects from Scilab
* @author Vincent COUVERT
}
/**
+ * Unblock the console if it is in "Continue display..." mode
+ */
+ public static void unblockConsole() {
+ SwingScilabConsole sciConsole = ((SwingScilabConsole) ScilabConsole.getConsole().getAsSimpleConsole());
+ sciConsole.unblock();
+ }
+
+ /**
* Save the main Window size and position
*/
public static void saveMainWindowSettings() {
SwingScilabMenuItem cutMenu = new SwingScilabMenuItem();
cutMenu.setText(Messages.gettext("Cut"));
cutMenu.setCallback(ScilabCallBack.createCallback(
- "org.scilab.modules.gui.bridge.CallScilabBridge.cutConsoleSelection",
- ScilabCallBack.JAVA));
+ "org.scilab.modules.gui.bridge.CallScilabBridge.cutConsoleSelection",
+ ScilabCallBack.JAVA));
cutMenu.setMnemonic('U');
SwingScilabMenuItem copyMenu = new SwingScilabMenuItem();
copyMenu.setText(Messages.gettext("Copy"));
copyMenu.setCallback(ScilabCallBack.createCallback(
- "org.scilab.modules.gui.bridge.CallScilabBridge.copyConsoleSelection",
- ScilabCallBack.JAVA));
+ "org.scilab.modules.gui.bridge.CallScilabBridge.copyConsoleSelection",
+ ScilabCallBack.JAVA));
copyMenu.setMnemonic('C');
SwingScilabMenuItem pasteMenu = new SwingScilabMenuItem();
pasteMenu.setText(Messages.gettext("Paste"));
pasteMenu.setCallback(ScilabCallBack.createCallback(
- "org.scilab.modules.gui.bridge.CallScilabBridge.pasteClipboardIntoConsole",
- ScilabCallBack.JAVA));
+ "org.scilab.modules.gui.bridge.CallScilabBridge.pasteClipboardIntoConsole",
+ ScilabCallBack.JAVA));
pasteMenu.setMnemonic('P');
SwingScilabMenuItem clearHistoryMenu = new SwingScilabMenuItem();
clearHistoryMenu.setText(Messages.gettext("Clear History"));
clearHistoryMenu.setCallback(ScilabCallBack.createCallback(
- "org.scilab.modules.gui.bridge.CallScilabBridge.clearHistory",
- ScilabCallBack.JAVA));
+ "org.scilab.modules.gui.bridge.CallScilabBridge.clearHistory",
+ ScilabCallBack.JAVA));
clearHistoryMenu.setMnemonic('H');
SwingScilabMenuItem clearMenu = new SwingScilabMenuItem();
clearMenu.setText(Messages.gettext("Clear Console"));
clearMenu.setCallback(ScilabCallBack.createCallback(
- "org.scilab.modules.gui.bridge.CallScilabBridge.clear",
- ScilabCallBack.JAVA));
+ "org.scilab.modules.gui.bridge.CallScilabBridge.clear",
+ ScilabCallBack.JAVA));
clearMenu.setMnemonic('O');
SwingScilabMenuItem selectMenu = new SwingScilabMenuItem();
selectMenu.setText(Messages.gettext("Select All"));
selectMenu.setCallback(ScilabCallBack.createCallback(
- "org.scilab.modules.gui.bridge.CallScilabBridge.selectAllConsoleContents",
- ScilabCallBack.JAVA));
+ "org.scilab.modules.gui.bridge.CallScilabBridge.selectAllConsoleContents",
+ ScilabCallBack.JAVA));
selectMenu.setMnemonic('S');
final SwingScilabMenuItem helpMenu = new SwingScilabMenuItem();
helpMenu.setText(Messages.gettext("Help on a selected keyword"));
helpMenu.setCallback(ScilabCallBack.createCallback(
- "org.scilab.modules.gui.bridge.CallScilabBridge.helpOnTheKeyword",
- ScilabCallBack.JAVA));
+ "org.scilab.modules.gui.bridge.CallScilabBridge.helpOnTheKeyword",
+ ScilabCallBack.JAVA));
helpMenu.setMnemonic('M');
PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent arg0) {
}
/**
+ * Unblock the console if needed
+ */
+ public void unblock() {
+ if (getCanReadUserInputValue().availablePermits() == 0) {
+ setUserInputValue((int) 'n');
+ }
+ }
+
+ /**
* Reads one user input char
* @return the data entered by the user
* @see fr.scilab.console.HelpBrowser#getCharWithoutOutput()
super(new BorderLayout());
jhelp = new JHelp();
add(jhelp);
+ setFocusable(true);
searchField = new HelpSearchField(this, null);
/* Send information to the user using status bar and cursor */
}
/**
+ * @return the current URL as String being displayed
+ */
+ public String getCurrentURL() {
+ return ((SwingScilabHelpBrowserViewer) jhelp.getContentViewer().getUI()).getCurrentURL();
+ }
+
+ /**
* Show the search field
*/
public void showSearchField() {
*/
public void displayHomePage() {
if (homePageURL != null) {
- jhelp.setCurrentURL(homePageURL);
+ setCurrentURL(homePageURL);
}
}
/**
+ * Sets the current URL
+ * @param url the URL to display
+ */
+ public void setCurrentURL(final URL url) {
+ SwingUtilities.invokeLater(new Runnable() {
+
+ public void run() {
+ jhelp.setCurrentURL(url);
+ }
+ });
+ }
+
+ /**
+ * Sets the current url
+ * @param url the url as String to display
+ */
+ public void setCurrentURL(String url) {
+ URL u = homePageURL;
+ try {
+ if (url != null) {
+ u = new URL(url);
+ }
+ } catch (MalformedURLException e) { }
+ setCurrentURL(u);
+ }
+
+ /**
* Display the Help Browser
*/
public void display() { }
*/
package org.scilab.modules.gui.bridge.helpbrowser;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.DefaultFocusTraversalPolicy;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseWheelEvent;
}
/**
+ * @return the current URL as String being displayed
+ */
+ public String getCurrentURL() {
+ return x.getCurrentURL().toString();
+ }
+
+ /**
* Execute the code in example
* @param pre the preformatted Element containing Scilab's code
*/
this.accessibleHtml = (javax.swing.JEditorPane) privateField.get(this);
accessibleHtml.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
+ // Crappy workaround to avoid bad html display (the icons play and edit can be misplaced)
+ // To improve... (it doesn't always work)
if (evt.getPropertyName().equals("document")) {
accessibleHtml.setVisible(false);
+ accessibleHtml.validate();
}
if (evt.getPropertyName().equals("page")) {
if (!accessibleHtml.isVisible()) {
}
});
+ // The previous workaround hides the component accessibleHtml
+ // and consequently the focus is given to an other component.
+ // So we force the accessibleHtml to keep the focus.
+ accessibleHtml.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
+ public Component getFirstComponent(Container aContainer) {
+ return x;
+ }
+ });
+ accessibleHtml.setFocusCycleRoot(true);
+
accessibleHtml.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ScilabKeyStroke.getKeyStroke("OSSCKEY shift EQUALS"), SHIFTEQ);
accessibleHtml.getActionMap().put(SHIFTEQ, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
/* Execute into Scilab */
ActionListener actionListenerExecuteIntoScilab = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- String selection = accessibleHtml.getSelectedText();
- if (selection == null) {
- ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
- } else {
- ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(selection, true /* display */, true /* store in history */);
+ public void actionPerformed(ActionEvent actionEvent) {
+ String selection = accessibleHtml.getSelectedText();
+ if (selection == null) {
+ ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
+ } else {
+ ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(selection, true /* display */, true /* store in history */);
+ }
}
- }
- };
+ };
menuItem = new JMenuItem(Messages.gettext("Execute into Scilab"));
menuItem.addActionListener(actionListenerExecuteIntoScilab);
if (!ScilabConsole.isExistingConsole()) { /* Only available in STD mode */
/* Edit in the Scilab Text Editor */
ActionListener actionListenerLoadIntoTextEditor = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- String selection = accessibleHtml.getSelectedText();
- if (selection == null) {
- ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
- } else {
- edit(selection);
+ public void actionPerformed(ActionEvent actionEvent) {
+ String selection = accessibleHtml.getSelectedText();
+ if (selection == null) {
+ ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
+ } else {
+ edit(selection);
+ }
}
- }
- };
+ };
menuItem = new JMenuItem(Messages.gettext("Edit in the Scilab Text Editor"));
try {
/* Back in the history*/
ActionListener actionListenerBackHistory = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
- /* Not at the first position */
- if (history.getIndex() > 0) {
- SwingScilabHelpBrowser.getHelpHistory().goBack();
+ public void actionPerformed(ActionEvent actionEvent) {
+ DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
+ /* Not at the first position */
+ if (history.getIndex() > 0) {
+ SwingScilabHelpBrowser.getHelpHistory().goBack();
+ }
}
- }
- };
+ };
menuItem = new JMenuItem(Messages.gettext("Back"));
menuItem.addActionListener(actionListenerBackHistory);
/* Forward in the history*/
ActionListener actionListenerForwardHistory = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
- /* Not at the last position */
- if (history.getHistory().size() != (history.getIndex() + 1)) {
- SwingScilabHelpBrowser.getHelpHistory().goForward();
+ public void actionPerformed(ActionEvent actionEvent) {
+ DefaultHelpHistoryModel history = SwingScilabHelpBrowser.getHelpHistory();
+ /* Not at the last position */
+ if (history.getHistory().size() != (history.getIndex() + 1)) {
+ SwingScilabHelpBrowser.getHelpHistory().goForward();
+ }
}
- }
- };
+ };
menuItem = new JMenuItem(Messages.gettext("Forward"));
menuItem.addActionListener(actionListenerForwardHistory);
/* Select all */
ActionListener actionListenerSelectAll = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- accessibleHtml.selectAll();
- }
- };
+ public void actionPerformed(ActionEvent actionEvent) {
+ accessibleHtml.selectAll();
+ }
+ };
menuItem = new JMenuItem(Messages.gettext("Select All"));
menuItem.addActionListener(actionListenerSelectAll);
popup.add(menuItem);
final JMenuItem helpMenuItem = new JMenuItem("Help on the selected text");
ActionListener actionListenerHelpOnKeyword= new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- String selection = accessibleHtml.getSelectedText();
- if (selection == null) {
- ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
- } else {
- ScilabHelpBrowser.getHelpBrowser().searchKeywork(selection);
+ public void actionPerformed(ActionEvent actionEvent) {
+ String selection = accessibleHtml.getSelectedText();
+ if (selection == null) {
+ ScilabHelpBrowser.getHelpBrowser().getInfoBar().setText(Messages.gettext("No text selected"));
+ } else {
+ ScilabHelpBrowser.getHelpBrowser().searchKeywork(selection);
+ }
}
- }
- };
+ };
PropertyChangeListener listenerTextItem = new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- String keyword = accessibleHtml.getSelectedText();
- if (keyword == null) {
- helpMenuItem.setText(Messages.gettext("Help about a selected text"));
- } else {
- int nbOfDisplayedOnlyXChar = 10;
- if (keyword.length() > nbOfDisplayedOnlyXChar) {
- keyword = keyword.substring(0, nbOfDisplayedOnlyXChar) + "...";
+ public void propertyChange(PropertyChangeEvent arg0) {
+ String keyword = accessibleHtml.getSelectedText();
+ if (keyword == null) {
+ helpMenuItem.setText(Messages.gettext("Help about a selected text"));
+ } else {
+ int nbOfDisplayedOnlyXChar = 10;
+ if (keyword.length() > nbOfDisplayedOnlyXChar) {
+ keyword = keyword.substring(0, nbOfDisplayedOnlyXChar) + "...";
+ }
+ helpMenuItem.setText(Messages.gettext("Help about '") +keyword+"'");
}
- helpMenuItem.setText(Messages.gettext("Help about '") +keyword+"'");
}
- }
- };
+ };
helpMenuItem.addPropertyChangeListener(listenerTextItem);
helpMenuItem.addActionListener(actionListenerHelpOnKeyword);
popup.add(helpMenuItem);
import org.scilab.modules.gui.console.ScilabConsole;
import org.scilab.modules.gui.messagebox.SimpleMessageBox;
+import org.scilab.modules.gui.tab.SimpleTab;
import org.scilab.modules.gui.tab.Tab;
import org.scilab.modules.gui.utils.ScilabSwingUtilities;
import org.scilab.modules.gui.utils.WebBrowser;
*/
public class SwingScilabMessageBox extends JDialog implements SimpleMessageBox, ActionListener {
- private static final long serialVersionUID = 7939976395338222763L;
-
- private static final int WINDOW_WIDTH = 650;
- private static final int MESSAGE_HEIGHT = 200;
- private static final int LISTBOX_HEIGHT = 200;
-
- private static final int X_MDIALOG_MARGIN = 5;
- private static final int X_MDIALOG_TEXTFIELD_SIZE = 10;
-
- private static final int X_MESSAGE_TYPE = 0;
- private static final int X_DIALOG_TYPE = 1;
- private static final int X_CHOOSE_TYPE = 2;
- private static final int X_MDIALOG_TYPE = 3;
- private static final int X_CHOICES_TYPE = 4;
-
- private static final String SCIDIR = System.getenv("SCI");
-
- /**
- * Offset around object and its ScrollPane
- */
- private static final int OFFSET = 5;
-
- /**
- * New line character for mutli-line text components
- */
- private static final String NEW_LINE = "\n";
-
- /**
- * Separator used for x_choices
- */
- private static final String SEPARATOR = "[--sep--]";
-
- /**
- * Icons
- */
- private Icon scilabIcon = new ImageIcon(SCIDIR + "/modules/gui/images/icons/scilab.png");
- private Icon passwdIcon = new ImageIcon(SCIDIR + "/modules/gui/images/icons/emblem-readonly.png");
- private Icon hourglassIcon = new ImageIcon(SCIDIR + "/modules/gui/images/icons/process-working.png");
-
- private int elementId;
-
- private Icon messageIcon; //= new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/scilab.png");
-
- private int scilabDialogType = X_MESSAGE_TYPE;
-
- private Component parentWindow;
-
- private JButton btnOK = new JButton("OK");
- private JButton btnCancel = new JButton("Cancel");
-
- /**
- * Used for x_dialog
- */
- private JTextArea textArea;
- private String initialValue;
- private int initialValueSize;
- private String userValue;
-
- /**
- * Used for x_choose
- */
- private JList listBox;
- private String[] listboxItems;
- private int selectedItem;
-
- /**
- * Used for x_mdialog
- */
- private String[] lineLabels;
- private String[] columnLabels;
- private String[] defaultInput;
- private JTextField[] textFields;
- private String[] userValues;
-
- /**
- * Used for x_choose & x_message
- */
- private String[] buttonsLabels;
- private int selectedButton;
-
- /**
- * Used for x_choices
- */
- private int[] defaultSelectedButtons;
- private ButtonGroup[] buttonGroups;
- private int[] userSelectedButtons;
-
- /**
- * Used for all Message Boxes
- */
- private String message;
- private String title;
- private Image imageForIcon = ((ImageIcon) scilabIcon).getImage();
- private int messageType = -1;
- private Object[] objs;
- private Object[] buttons;
- private boolean modal = true;
-
- /**
- * Default constructor
- */
- public SwingScilabMessageBox() {
- super(new JFrame());
- ((JFrame) getOwner()).setIconImage(imageForIcon); // Java 1.5 compatible
+ private static final long serialVersionUID = 7939976395338222763L;
+
+ private static final int WINDOW_WIDTH = 650;
+ private static final int MESSAGE_HEIGHT = 200;
+ private static final int LISTBOX_HEIGHT = 200;
+
+ private static final int X_MDIALOG_MARGIN = 5;
+ private static final int X_MDIALOG_TEXTFIELD_SIZE = 10;
+
+ private static final int X_MESSAGE_TYPE = 0;
+ private static final int X_DIALOG_TYPE = 1;
+ private static final int X_CHOOSE_TYPE = 2;
+ private static final int X_MDIALOG_TYPE = 3;
+ private static final int X_CHOICES_TYPE = 4;
+
+ private static final String SCIDIR = System.getenv("SCI");
+
+ /**
+ * Offset around object and its ScrollPane
+ */
+ private static final int OFFSET = 5;
+
+ /**
+ * New line character for mutli-line text components
+ */
+ private static final String NEW_LINE = "\n";
+
+ /**
+ * Separator used for x_choices
+ */
+ private static final String SEPARATOR = "[--sep--]";
+
+ /**
+ * Icons
+ */
+ private Icon scilabIcon = new ImageIcon(SCIDIR + "/modules/gui/images/icons/scilab.png");
+ private Icon passwdIcon = new ImageIcon(SCIDIR + "/modules/gui/images/icons/emblem-readonly.png");
+ private Icon hourglassIcon = new ImageIcon(SCIDIR + "/modules/gui/images/icons/process-working.png");
+
+ private int elementId;
+
+ private Icon messageIcon; //= new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/scilab.png");
+
+ private int scilabDialogType = X_MESSAGE_TYPE;
+
+ private Component parentWindow;
+
+ private JButton btnOK = new JButton("OK");
+ private JButton btnCancel = new JButton("Cancel");
+
+ /**
+ * Used for x_dialog
+ */
+ private JTextArea textArea;
+ private String initialValue;
+ private int initialValueSize;
+ private String userValue;
+
+ /**
+ * Used for x_choose
+ */
+ private JList listBox;
+ private String[] listboxItems;
+ private int selectedItem;
+
+ /**
+ * Used for x_mdialog
+ */
+ private String[] lineLabels;
+ private String[] columnLabels;
+ private String[] defaultInput;
+ private JTextField[] textFields;
+ private String[] userValues;
+
+ /**
+ * Used for x_choose & x_message
+ */
+ private String[] buttonsLabels;
+ private int selectedButton;
+
+ /**
+ * Used for x_choices
+ */
+ private int[] defaultSelectedButtons;
+ private ButtonGroup[] buttonGroups;
+ private int[] userSelectedButtons;
+
+ /**
+ * Used for all Message Boxes
+ */
+ private String message;
+ private String title;
+ private Image imageForIcon = ((ImageIcon) scilabIcon).getImage();
+ private int messageType = -1;
+ private Object[] objs;
+ private Object[] buttons;
+ private boolean modal = true;
+
+ /**
+ * Default constructor
+ */
+ public SwingScilabMessageBox() {
+ super(new JFrame());
+ ((JFrame) getOwner()).setIconImage(imageForIcon); // Java 1.5 compatible
+ }
+
+ /**
+ * Set the element id for this MessageBox
+ * @param id the id of the corresponding MessageBox object
+ */
+ public void setElementId(int id) {
+ this.elementId = id;
+ }
+
+ /**
+ * Get the element id for MessageBox
+ * @return id the id of the corresponding MessageBox object
+ */
+ public int getElementId() {
+ return this.elementId;
+ }
+
+ /**
+ * Set the title of the MessageBox
+ * @param title the title to set
+ */
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ /**
+ * Set the message of the MessageBox
+ * @param message the message to set
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ /**
+ * Set the message of the MessageBox (multi-line)
+ * @param mess the message to set
+ */
+ public void setMessage(String[] mess) {
+ int line = 0;
+ message = "<HTML>";
+ for (line = 0; line < mess.length - 1; line++) {
+ message += "<div>" + mess[line] + "</div>";
}
-
- /**
- * Set the element id for this MessageBox
- * @param id the id of the corresponding MessageBox object
- */
- public void setElementId(int id) {
- this.elementId = id;
- }
-
- /**
- * Get the element id for MessageBox
- * @return id the id of the corresponding MessageBox object
- */
- public int getElementId() {
- return this.elementId;
- }
-
- /**
- * Set the title of the MessageBox
- * @param title the title to set
- */
- public void setTitle(String title) {
- this.title = title;
- }
-
- /**
- * Set the message of the MessageBox
- * @param message the message to set
- */
- public void setMessage(String message) {
- this.message = message;
- }
-
- /**
- * Set the message of the MessageBox (multi-line)
- * @param mess the message to set
- */
- public void setMessage(String[] mess) {
- int line = 0;
- message = "<HTML>";
- for (line = 0; line < mess.length - 1; line++) {
- message += "<div>" + mess[line] + "</div>";
+ message += mess[line] + "</HTML>";
+ }
+
+ /**
+ * DefaultValues
+ * Display this MessageBox and wait for user selection
+ */
+ public void displayAndWait() {
+
+ // Set the title & icon
+ //setIconImage(imageForIcon); // Not Java 1.5 compatible
+ super.setTitle(title);
+
+ // Create the message to display
+ JTextPane messageLabel = new JTextPane();
+ messageLabel.setContentType("text/html");
+ messageLabel.setOpaque(false);
+ messageLabel.setBorder(null);
+ messageLabel.setEditable(false);
+
+ // Update the stylesheet so that the font matches JLabel font
+ Font labelFont = UIManager.getFont("Label.font");
+ HTMLEditorKit editorKit = (HTMLEditorKit) messageLabel.getEditorKit();
+ StyleSheet styles = editorKit.getStyleSheet();
+ String css = "body {font-family:\"" + labelFont.getName()
+ + "\"; font-size:\"" + labelFont.getSize() + "pt\"}";
+ styles.addRule(css);
+ editorKit.setStyleSheet(styles);
+ messageLabel.setEditorKit(editorKit);
+
+ messageLabel.setText(message);
+
+ /* Add a link to make HTML links active */
+ messageLabel.addHyperlinkListener(new HyperlinkListener() {
+ public void hyperlinkUpdate(HyperlinkEvent e) {
+ if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+ WebBrowser.openUrl(e.getURL(), e.getDescription());
+ }
}
- message += mess[line] + "</HTML>";
- }
-
- /**
- * DefaultValues
- * Display this MessageBox and wait for user selection
- */
- public void displayAndWait() {
-
- // Set the title & icon
- //setIconImage(imageForIcon); // Not Java 1.5 compatible
- super.setTitle(title);
-
- // Create the message to display
- JTextPane messageLabel = new JTextPane();
- messageLabel.setContentType("text/html");
- messageLabel.setOpaque(false);
- messageLabel.setBorder(null);
- messageLabel.setEditable(false);
-
- // Update the stylesheet so that the font matches JLabel font
- Font labelFont = UIManager.getFont("Label.font");
- HTMLEditorKit editorKit = (HTMLEditorKit) messageLabel.getEditorKit();
- StyleSheet styles = editorKit.getStyleSheet();
- String css = "body {font-family:\"" + labelFont.getName()
- + "\"; font-size:\"" + labelFont.getSize() + "pt\"}";
- styles.addRule(css);
- editorKit.setStyleSheet(styles);
- messageLabel.setEditorKit(editorKit);
-
- messageLabel.setText(message);
-
- /* Add a link to make HTML links active */
- messageLabel.addHyperlinkListener(new HyperlinkListener() {
- public void hyperlinkUpdate(HyperlinkEvent e) {
- if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
- WebBrowser.openUrl(e.getURL(), e.getDescription());
- }
- }
- });
-
- JScrollPane messageScrollPane = new JScrollPane(messageLabel);
- int scrollWidth = (int) Math.min(WINDOW_WIDTH, messageLabel.getPreferredSize().getWidth() + OFFSET);
- int scrollHeight = (int) Math.min(MESSAGE_HEIGHT, messageLabel.getPreferredSize().getHeight() + OFFSET);
- messageScrollPane.setPreferredSize(new Dimension(scrollWidth, scrollHeight));
- // Make the scroll Pane transparent
- messageScrollPane.setOpaque(false);
- messageScrollPane.getViewport().setOpaque(false);
- /* Make the Border of the ScrollPane invisible */
- messageScrollPane.setBorder(BorderFactory.createEmptyBorder());
- messageScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
-
- if (scilabDialogType == X_CHOICES_TYPE) {
- // Create a MessageBox for Scilab x_choices
-
- // All objects in the MessageBox:
- // - Message
- // - Editable zone
- objs = new Object[2];
-
- objs[0] = messageScrollPane;
-
- // Search the max number of objects in a line
- int curNumber = 0;
- int numberOfLines = 0;
- int numberOfColumns = 0;
- List<Integer> buttonsPerLines = new ArrayList<Integer>();
- for (int itemIndex = 0; itemIndex < lineLabels.length; itemIndex++) {
- if (!lineLabels[itemIndex].equals(SEPARATOR)) {
- curNumber++;
- } else {
- if (curNumber > numberOfColumns) {
- numberOfColumns = curNumber;
- }
- // Store informations of current line
- buttonsPerLines.add(curNumber);
- curNumber = 0;
- numberOfLines++;
- }
- }
- // Store information of last line
- // Because no separator after last line items
- buttonsPerLines.add(curNumber);
- numberOfLines++;
-
- // Create the panel with button groups
- JPanel panel = new JPanel(new GridBagLayout());
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- buttonGroups = new ButtonGroup[numberOfLines];
-
- // Initialize return value
- userSelectedButtons = new int[numberOfLines];
-
- int curItemIndex = 0;
- int lineNumber = 0;
- int buttonNumber = 0;
- for (curItemIndex = 0; curItemIndex < lineLabels.length; curItemIndex++) {
- // Add the label of the line
- gbc.weightx = 1; // Labels will use remaining space when resizing
- panel.add(new JLabel(lineLabels[curItemIndex]), gbc);
- gbc.gridx++; // Increment the column index
-
- buttonNumber = 0;
- curItemIndex++;
-
- // Add the button group
- ButtonGroup group = new ButtonGroup();
- while (curItemIndex < lineLabels.length && !lineLabels[curItemIndex].equals(SEPARATOR)) {
- // Add a toggle button
- JToggleButton button = new JToggleButton(lineLabels[curItemIndex]);
- buttonNumber++;
-
- // Select this button if default
- if (buttonNumber == defaultSelectedButtons[lineNumber]) {
- button.setSelected(true);
- }
- // Select this button if default selection is a non existing button
- // And this button is the last of the line
- if (buttonNumber == (buttonsPerLines.get(lineNumber) - 1)
- && defaultSelectedButtons[lineNumber] > (buttonsPerLines.get(lineNumber) - 1)) {
- button.setSelected(true);
- }
- // Add the button to the group (for toggle)
- // And to the panel (for display)
- group.add(button);
- gbc.weightx = 0; // Button size will not change when resizing
- panel.add(button, gbc);
- gbc.gridx++; // Increment the column index
-
- // Increment item index
- curItemIndex++;
-
- }
- // Add empty labels if number of buttons in the line is lesser than maximum number of buttons found in a line
- for (int emptyLabelsIndex = buttonsPerLines.get(lineNumber); emptyLabelsIndex < numberOfColumns; emptyLabelsIndex++) {
- panel.add(new JLabel(), gbc);
- gbc.gridx++; // Increment the column index
- }
-
- // Store the group to get the user selection when returning
- buttonGroups[lineNumber] = group;
-
- // Increment current line number
- lineNumber++;
- gbc.gridx = 0; // New line --> Back to first column
- gbc.gridy++; // Increment the row index
- }
-
- // Display the panel
- panel.doLayout();
-
- // Editable text zone
- JScrollPane scrollPane = new JScrollPane(panel);
-
- scrollWidth = (int) Math.min(WINDOW_WIDTH, panel.getPreferredSize().getWidth() + OFFSET);
- scrollHeight = (int) Math.min(LISTBOX_HEIGHT, panel.getPreferredSize().getHeight() + OFFSET);
- scrollPane.setPreferredSize(new Dimension(scrollWidth, scrollHeight));
-
- objs[1] = scrollPane;
-
- // And now the buttons
- buttons = new Object[2];
- btnOK.addActionListener(this);
- btnCancel.addActionListener(this);
- /* Test added for bug 4347 fix */
- if (isWindows()) {
- buttons[0] = btnOK;
- buttons[1] = btnCancel;
-
- } else {
- buttons[0] = btnCancel;
- buttons[1] = btnOK;
- }
- } else if (scilabDialogType == X_MDIALOG_TYPE) {
- // Create a MessageBox for Scilab x_mdialog
-
- // All objects in the MessageBox:
- // - Message
- // - Editable zone
- objs = new Object[2];
-
- objs[0] = messageScrollPane;
-
- int numberOfColumns = 0;
- if (columnLabels == null) {
- numberOfColumns = 2;
- } else {
- numberOfColumns = columnLabels.length + 1;
- }
- GridBagLayout layout = new GridBagLayout();
- JPanel panel = new JPanel(layout);
- GridBagConstraints constraints = new GridBagConstraints();
- constraints.gridx = 0;
- constraints.gridy = 0;
- constraints.fill = GridBagConstraints.HORIZONTAL;
- constraints.insets = new Insets(X_MDIALOG_MARGIN, X_MDIALOG_MARGIN, X_MDIALOG_MARGIN, X_MDIALOG_MARGIN);
-
- int line = 0;
- int col = 0;
- // Optional first line
- if (columnLabels != null) {
- // Column label for "Row labels" column
- panel.add(new JLabel(""), constraints);
- constraints.gridx++;
- for (col = 0; col < columnLabels.length; col++) {
- panel.add(new JLabel(columnLabels[col]), constraints);
- constraints.gridx++;
- }
- constraints.gridy++;
- }
-
-
- // Prepare return value
- if (columnLabels == null) {
- userValues = new String[lineLabels.length];
- textFields = new JTextField[lineLabels.length];
- } else {
- userValues = new String[lineLabels.length * columnLabels.length];
- textFields = new JTextField[lineLabels.length * columnLabels.length];
- }
- for (line = 0; line < lineLabels.length; line++) {
- constraints.gridx = 0;
- panel.add(new JLabel(lineLabels[line]), constraints);
- constraints.gridx++;
- for (col = 0; col < numberOfColumns - 1; col++) {
- textFields[col * lineLabels.length + line] = new JTextField(defaultInput[col * lineLabels.length + line]);
- panel.add(textFields[col * lineLabels.length + line], constraints);
- textFields[col * lineLabels.length + line].setColumns(X_MDIALOG_TEXTFIELD_SIZE);
- constraints.gridx++;
- }
- constraints.gridy++;
- }
-
- panel.doLayout();
-
- // Editable text zone
- JScrollPane scrollPane = new JScrollPane(panel);
-
- scrollWidth = (int) Math.min(WINDOW_WIDTH, panel.getPreferredSize().getWidth() + OFFSET);
- scrollHeight = (int) Math.min(LISTBOX_HEIGHT, panel.getPreferredSize().getHeight() + OFFSET);
- scrollPane.setPreferredSize(new Dimension(scrollWidth, scrollHeight));
-
- objs[1] = scrollPane;
-
- // And now the buttons
- buttons = new Object[2];
- btnOK.addActionListener(this);
- btnCancel.addActionListener(this);
- /* Test added for bug 4347 fix */
- if (isWindows()) {
- buttons[0] = btnOK;
- buttons[1] = btnCancel;
-
- } else {
- buttons[0] = btnCancel;
- buttons[1] = btnOK;
- }
- } else if (scilabDialogType == X_CHOOSE_TYPE) {
- // Create a MessageBox for Scilab x_choose
-
- // All objects in the MessageBox:
- // - Message
- // - Listbox
- objs = new Object[2];
-
- // Add the message
- objs[0] = messageScrollPane;
-
- // Add the listBox
- objs[1] = createXchooseListBox();
-
- // And now the buttons
- buttons = new Object[1];
- if (buttonsLabels != null) {
- btnCancel.setText(buttonsLabels[0]);
- }
- btnCancel.addActionListener(this);
- buttons[0] = btnCancel;
- } else if (scilabDialogType == X_DIALOG_TYPE) {
- // Create a MessageBox for Scilab x_dialog
-
- // All objects in the MessageBox:
- // - Message
- // - Editable zone
- objs = new Object[2];
-
- objs[0] = messageScrollPane;
-
- // Editable text zone
- textArea = new JTextArea(initialValue);
- textArea.setRows(initialValueSize);
- JScrollPane scrollPane = new JScrollPane(textArea);
- scrollWidth = (int) Math.min(WINDOW_WIDTH, textArea.getPreferredSize().getWidth() + OFFSET);
- scrollHeight = (int) Math.min(LISTBOX_HEIGHT, textArea.getPreferredSize().getHeight() + OFFSET);
- scrollPane.setPreferredSize(new Dimension(scrollWidth, scrollHeight));
-
- objs[1] = scrollPane;
-
- // And now the buttons
- buttons = new Object[2];
- btnOK.addActionListener(this);
- btnCancel.addActionListener(this);
- /* Test added for bug 4347 fix */
- if (isWindows()) {
- buttons[0] = btnOK;
- buttons[1] = btnCancel;
-
- } else {
- buttons[0] = btnCancel;
- buttons[1] = btnOK;
- }
- } else {
- // Create a MessageBox for Scilab x_message
-
- // All objects in the MessageBox:
- // - Message
- objs = new Object[1];
-
- // Add the message
- objs[0] = messageScrollPane;
-
- // And now the buttons
- if (buttonsLabels == null) {
- buttons = new Object[1];
- btnOK.addActionListener(this);
- buttons[0] = btnOK;
- //messageType = JOptionPane.INFORMATION_MESSAGE;
- } else {
- buttons = new Object[buttonsLabels.length];
- for (int buttonNb = 0; buttonNb < buttonsLabels.length; buttonNb++) {
- JButton currentButton = new JButton(buttonsLabels[buttonNb]);
- currentButton.addActionListener(this);
- /* Test added for bug 4347 fix */
- if (isWindows()) {
- buttons[buttonNb] = currentButton;
- } else {
- buttons[buttonsLabels.length - buttonNb - 1] = currentButton;
- }
- }
- }
- }
- // Display
- ((JScrollPane) objs[0]).setBorder(BorderFactory.createEmptyBorder());
- if (messageType != -1) {
- setContentPane(new JOptionPane(objs, messageType, JOptionPane.CANCEL_OPTION, null, buttons));
+ });
+
+ JScrollPane messageScrollPane = new JScrollPane(messageLabel);
+ int scrollWidth = (int) Math.min(WINDOW_WIDTH, messageLabel.getPreferredSize().getWidth() + OFFSET);
+ int scrollHeight = (int) Math.min(MESSAGE_HEIGHT, messageLabel.getPreferredSize().getHeight() + OFFSET);
+ messageScrollPane.setPreferredSize(new Dimension(scrollWidth, scrollHeight));
+ // Make the scroll Pane transparent
+ messageScrollPane.setOpaque(false);
+ messageScrollPane.getViewport().setOpaque(false);
+ /* Make the Border of the ScrollPane invisible */
+ messageScrollPane.setBorder(BorderFactory.createEmptyBorder());
+ messageScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
+
+ if (scilabDialogType == X_CHOICES_TYPE) {
+ // Create a MessageBox for Scilab x_choices
+
+ // All objects in the MessageBox:
+ // - Message
+ // - Editable zone
+ objs = new Object[2];
+
+ objs[0] = messageScrollPane;
+
+ // Search the max number of objects in a line
+ int curNumber = 0;
+ int numberOfLines = 0;
+ int numberOfColumns = 0;
+ List<Integer> buttonsPerLines = new ArrayList<Integer>();
+ for (int itemIndex = 0; itemIndex < lineLabels.length; itemIndex++) {
+ if (!lineLabels[itemIndex].equals(SEPARATOR)) {
+ curNumber++;
} else {
- if (messageIcon == null) {
- messageIcon = scilabIcon;
- }
- setContentPane(new JOptionPane(objs, messageType, JOptionPane.CANCEL_OPTION, messageIcon, buttons));
+ if (curNumber > numberOfColumns) {
+ numberOfColumns = curNumber;
+ }
+ // Store informations of current line
+ buttonsPerLines.add(curNumber);
+ curNumber = 0;
+ numberOfLines++;
}
- pack();
- super.setModal(modal); /* Must call the JDialog class setModal */
+ }
+ // Store information of last line
+ // Because no separator after last line items
+ buttonsPerLines.add(curNumber);
+ numberOfLines++;
+
+ // Create the panel with button groups
+ JPanel panel = new JPanel(new GridBagLayout());
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ buttonGroups = new ButtonGroup[numberOfLines];
+
+ // Initialize return value
+ userSelectedButtons = new int[numberOfLines];
+
+ int curItemIndex = 0;
+ int lineNumber = 0;
+ int buttonNumber = 0;
+ for (curItemIndex = 0; curItemIndex < lineLabels.length; curItemIndex++) {
+ // Add the label of the line
+ gbc.weightx = 1; // Labels will use remaining space when resizing
+ panel.add(new JLabel(lineLabels[curItemIndex]), gbc);
+ gbc.gridx++; // Increment the column index
+
+ buttonNumber = 0;
+ curItemIndex++;
+
+ // Add the button group
+ ButtonGroup group = new ButtonGroup();
+ while (curItemIndex < lineLabels.length && !lineLabels[curItemIndex].equals(SEPARATOR)) {
+ // Add a toggle button
+ JToggleButton button = new JToggleButton(lineLabels[curItemIndex]);
+ buttonNumber++;
+
+ // Select this button if default
+ if (buttonNumber == defaultSelectedButtons[lineNumber]) {
+ button.setSelected(true);
+ }
+ // Select this button if default selection is a non existing button
+ // And this button is the last of the line
+ if (buttonNumber == (buttonsPerLines.get(lineNumber) - 1)
+ && defaultSelectedButtons[lineNumber] > (buttonsPerLines.get(lineNumber) - 1)) {
+ button.setSelected(true);
+ }
+ // Add the button to the group (for toggle)
+ // And to the panel (for display)
+ group.add(button);
+ gbc.weightx = 0; // Button size will not change when resizing
+ panel.add(button, gbc);
+ gbc.gridx++; // Increment the column index
+
+ // Increment item index
+ curItemIndex++;
- if (parentWindow == null) {
- if (ScilabConsole.isExistingConsole()) {
- setLocationRelativeTo((Component) ScilabConsole.getConsole().getAsSimpleConsole());
- }
- } else {
- setLocationRelativeTo(parentWindow);
}
-
- ScilabSwingUtilities.closeOnEscape(this);
-
- setVisible(true);
- doLayout();
-
- // If the dialog is not modal and Scilab waits for an answer, have to wait...
- if (!modal && scilabDialogType != X_MESSAGE_TYPE) {
- synchronized (btnOK) {
- try {
- btnOK.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
+ // Add empty labels if number of buttons in the line is lesser than maximum number of buttons found in a line
+ for (int emptyLabelsIndex = buttonsPerLines.get(lineNumber); emptyLabelsIndex < numberOfColumns; emptyLabelsIndex++) {
+ panel.add(new JLabel(), gbc);
+ gbc.gridx++; // Increment the column index
}
- }
- /**
- * Action management
- * @param ae the action event
- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
- */
-
- public void actionPerformed(ActionEvent ae) {
- if (ae.getSource() == btnOK) {
- // For a x_dialog, get the user answer
- if (scilabDialogType == X_DIALOG_TYPE) {
- userValue = textArea.getText();
- } else if (scilabDialogType == X_MDIALOG_TYPE) {
- for (int textFieldIndex = 0; textFieldIndex < textFields.length; textFieldIndex++) {
- userValues[textFieldIndex] = textFields[textFieldIndex].getText();
- }
- userValue = ""; /* To make getValueSize return a non zero value */
- } else if (scilabDialogType == X_CHOICES_TYPE) {
-
- // Get the selected button index of each button group
- for (int groupNum = 0; groupNum < buttonGroups.length; groupNum++) {
- Enumeration<AbstractButton> theButtons = buttonGroups[groupNum].getElements();
- for (int btnNum = 0; btnNum < buttonGroups[groupNum].getButtonCount(); btnNum++) {
- JToggleButton b = (JToggleButton) theButtons.nextElement();
- if (b.getModel() == buttonGroups[groupNum].getSelection()) {
- userSelectedButtons[groupNum] = btnNum + 1;
- }
- }
- }
- userValue = ""; /* To make getValueSize return a non zero value */
- }
- selectedButton = 1;
- } else if (ae.getSource() == btnCancel) {
- selectedButton = 2;
- } else if (buttonsLabels != null) { // User defined buttons
- for (int index = 0; index < buttonsLabels.length; index++) {
- if (((JButton) ae.getSource()).getText().equals(buttonsLabels[index])) {
- selectedButton = index + 1;
- break;
- }
- }
+ // Store the group to get the user selection when returning
+ buttonGroups[lineNumber] = group;
+
+ // Increment current line number
+ lineNumber++;
+ gbc.gridx = 0; // New line --> Back to first column
+ gbc.gridy++; // Increment the row index
+ }
+
+ // Display the panel
+ panel.doLayout();
+
+ // Editable text zone
+ JScrollPane scrollPane = new JScrollPane(panel);
+
+ scrollWidth = (int) Math.min(WINDOW_WIDTH, panel.getPreferredSize().getWidth() + OFFSET);
+ scrollHeight = (int) Math.min(LISTBOX_HEIGHT, panel.getPreferredSize().getHeight() + OFFSET);
+ scrollPane.setPreferredSize(new Dimension(scrollWidth, scrollHeight));
+
+ objs[1] = scrollPane;
+
+ // And now the buttons
+ buttons = new Object[2];
+ btnOK.addActionListener(this);
+ btnCancel.addActionListener(this);
+ /* Test added for bug 4347 fix */
+ if (isWindows()) {
+ buttons[0] = btnOK;
+ buttons[1] = btnCancel;
+
+ } else {
+ buttons[0] = btnCancel;
+ buttons[1] = btnOK;
+ }
+ } else if (scilabDialogType == X_MDIALOG_TYPE) {
+ // Create a MessageBox for Scilab x_mdialog
+
+ // All objects in the MessageBox:
+ // - Message
+ // - Editable zone
+ objs = new Object[2];
+
+ objs[0] = messageScrollPane;
+
+ int numberOfColumns = 0;
+ if (columnLabels == null) {
+ numberOfColumns = 2;
+ } else {
+ numberOfColumns = columnLabels.length + 1;
+ }
+ GridBagLayout layout = new GridBagLayout();
+ JPanel panel = new JPanel(layout);
+ GridBagConstraints constraints = new GridBagConstraints();
+ constraints.gridx = 0;
+ constraints.gridy = 0;
+ constraints.fill = GridBagConstraints.HORIZONTAL;
+ constraints.insets = new Insets(X_MDIALOG_MARGIN, X_MDIALOG_MARGIN, X_MDIALOG_MARGIN, X_MDIALOG_MARGIN);
+
+ int line = 0;
+ int col = 0;
+ // Optional first line
+ if (columnLabels != null) {
+ // Column label for "Row labels" column
+ panel.add(new JLabel(""), constraints);
+ constraints.gridx++;
+ for (col = 0; col < columnLabels.length; col++) {
+ panel.add(new JLabel(columnLabels[col]), constraints);
+ constraints.gridx++;
}
- // Notify btnOK for not modal Dialogs
- synchronized (btnOK) {
- btnOK.notify();
+ constraints.gridy++;
+ }
+
+
+ // Prepare return value
+ if (columnLabels == null) {
+ userValues = new String[lineLabels.length];
+ textFields = new JTextField[lineLabels.length];
+ } else {
+ userValues = new String[lineLabels.length * columnLabels.length];
+ textFields = new JTextField[lineLabels.length * columnLabels.length];
+ }
+ for (line = 0; line < lineLabels.length; line++) {
+ constraints.gridx = 0;
+ panel.add(new JLabel(lineLabels[line]), constraints);
+ constraints.gridx++;
+ for (col = 0; col < numberOfColumns - 1; col++) {
+ textFields[col * lineLabels.length + line] = new JTextField(defaultInput[col * lineLabels.length + line]);
+ panel.add(textFields[col * lineLabels.length + line], constraints);
+ textFields[col * lineLabels.length + line].setColumns(X_MDIALOG_TEXTFIELD_SIZE);
+ constraints.gridx++;
}
- // Destroy the Dialog
- dispose();
- }
- /**
- * Get the index of the button clicked
- * @return the index of the button clicked
- */
- public int getSelectedButton() {
- return selectedButton;
- }
-
- /**
- * Set the indices of the default selected buttons (x_choices)
- * @param indices the indices of the default selected buttons
- */
- public void setDefaultSelectedButtons(int[] indices) {
- defaultSelectedButtons = indices;
- scilabDialogType = X_CHOICES_TYPE;
+ constraints.gridy++;
+ }
+
+ panel.doLayout();
+
+ // Editable text zone
+ JScrollPane scrollPane = new JScrollPane(panel);
+
+ scrollWidth = (int) Math.min(WINDOW_WIDTH, panel.getPreferredSize().getWidth() + OFFSET);
+ scrollHeight = (int) Math.min(LISTBOX_HEIGHT, panel.getPreferredSize().getHeight() + OFFSET);
+ scrollPane.setPreferredSize(new Dimension(scrollWidth, scrollHeight));
+
+ objs[1] = scrollPane;
+
+ // And now the buttons
+ buttons = new Object[2];
+ btnOK.addActionListener(this);
+ btnCancel.addActionListener(this);
+ /* Test added for bug 4347 fix */
+ if (isWindows()) {
+ buttons[0] = btnOK;
+ buttons[1] = btnCancel;
+
+ } else {
+ buttons[0] = btnCancel;
+ buttons[1] = btnOK;
+ }
+ } else if (scilabDialogType == X_CHOOSE_TYPE) {
+ // Create a MessageBox for Scilab x_choose
+
+ // All objects in the MessageBox:
+ // - Message
+ // - Listbox
+ objs = new Object[2];
+
+ // Add the message
+ objs[0] = messageScrollPane;
+
+ // Add the listBox
+ objs[1] = createXchooseListBox();
+
+ // And now the buttons
+ buttons = new Object[1];
+ if (buttonsLabels != null) {
+ btnCancel.setText(buttonsLabels[0]);
+ }
+ btnCancel.addActionListener(this);
+ buttons[0] = btnCancel;
+ } else if (scilabDialogType == X_DIALOG_TYPE) {
+ // Create a MessageBox for Scilab x_dialog
+
+ // All objects in the MessageBox:
+ // - Message
+ // - Editable zone
+ objs = new Object[2];
+
+ objs[0] = messageScrollPane;
+
+ // Editable text zone
+ textArea = new JTextArea(initialValue);
+ textArea.setRows(initialValueSize);
+ JScrollPane scrollPane = new JScrollPane(textArea);
+ scrollWidth = (int) Math.min(WINDOW_WIDTH, textArea.getPreferredSize().getWidth() + OFFSET);
+ scrollHeight = (int) Math.min(LISTBOX_HEIGHT, textArea.getPreferredSize().getHeight() + OFFSET);
+ scrollPane.setPreferredSize(new Dimension(scrollWidth, scrollHeight));
+
+ objs[1] = scrollPane;
+
+ // And now the buttons
+ buttons = new Object[2];
+ btnOK.addActionListener(this);
+ btnCancel.addActionListener(this);
+ /* Test added for bug 4347 fix */
+ if (isWindows()) {
+ buttons[0] = btnOK;
+ buttons[1] = btnCancel;
+
+ } else {
+ buttons[0] = btnCancel;
+ buttons[1] = btnOK;
+ }
+ } else {
+ // Create a MessageBox for Scilab x_message
+
+ // All objects in the MessageBox:
+ // - Message
+ objs = new Object[1];
+
+ // Add the message
+ objs[0] = messageScrollPane;
+
+ // And now the buttons
+ if (buttonsLabels == null) {
+ buttons = new Object[1];
+ btnOK.addActionListener(this);
+ buttons[0] = btnOK;
+ //messageType = JOptionPane.INFORMATION_MESSAGE;
+ } else {
+ buttons = new Object[buttonsLabels.length];
+ for (int buttonNb = 0; buttonNb < buttonsLabels.length; buttonNb++) {
+ JButton currentButton = new JButton(buttonsLabels[buttonNb]);
+ currentButton.addActionListener(this);
+ /* Test added for bug 4347 fix */
+ if (isWindows()) {
+ buttons[buttonNb] = currentButton;
+ } else {
+ buttons[buttonsLabels.length - buttonNb - 1] = currentButton;
+ }
+ }
+ }
}
-
- /**
- * Get the indices of the selected buttons (x_choices)
- * @return the indices of the selected buttons
- */
- public int[] getUserSelectedButtons() {
- return userSelectedButtons;
+ // Display
+ ((JScrollPane) objs[0]).setBorder(BorderFactory.createEmptyBorder());
+ if (messageType != -1) {
+ setContentPane(new JOptionPane(objs, messageType, JOptionPane.CANCEL_OPTION, null, buttons));
+ } else {
+ if (messageIcon == null) {
+ messageIcon = scilabIcon;
+ }
+ setContentPane(new JOptionPane(objs, messageType, JOptionPane.CANCEL_OPTION, messageIcon, buttons));
}
-
- /**
- * Set the labels of the buttons in the MessageBox
- * @param labels the labels of the buttons
- */
- public void setButtonsLabels(String[] labels) {
- buttonsLabels = labels;
+ pack();
+ super.setModal(modal); /* Must call the JDialog class setModal */
+
+ if (parentWindow == null) {
+ if (ScilabConsole.isExistingConsole()) {
+ setLocationRelativeTo((Component) ScilabConsole.getConsole().getAsSimpleConsole());
+ }
+ } else {
+ setLocationRelativeTo(parentWindow);
}
- /**
- * Set the initial values of the editable zone in the MessageBox
- * @param value the initial values
- */
- public void setInitialValue(String[] value) {
- int line = 0;
- initialValue = "";
- for (line = 0; line < value.length - 1; line++) {
- initialValue += value[line] + NEW_LINE;
- }
- initialValue += value[line];
- initialValueSize = value.length;
+ ScilabSwingUtilities.closeOnEscape(this);
- scilabDialogType = X_DIALOG_TYPE;
- }
+ setVisible(true);
+ doLayout();
- /**
- * Get the value of the editable zone in the MessageBox
- * @return the value
- */
- public String[] getValue() {
- if (scilabDialogType == X_MDIALOG_TYPE) {
- return userValues;
- } else {
- return userValue.split(NEW_LINE);
+ // If the dialog is not modal and Scilab waits for an answer, have to wait...
+ if (!modal && scilabDialogType != X_MESSAGE_TYPE) {
+ synchronized (btnOK) {
+ try {
+ btnOK.wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
+ }
}
-
- /**
- * Get the size of the value of the editable zone in the MessageBox
- * @return the value size
- */
- public int getValueSize() {
- if (userValue == null) {
- return 0;
- } else {
- return userValue.split(NEW_LINE).length;
+ }
+
+ /**
+ * Action management
+ * @param ae the action event
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+
+ public void actionPerformed(ActionEvent ae) {
+ if (ae.getSource() == btnOK) {
+ // For a x_dialog, get the user answer
+ if (scilabDialogType == X_DIALOG_TYPE) {
+ userValue = textArea.getText();
+ } else if (scilabDialogType == X_MDIALOG_TYPE) {
+ for (int textFieldIndex = 0; textFieldIndex < textFields.length; textFieldIndex++) {
+ userValues[textFieldIndex] = textFields[textFieldIndex].getText();
}
- }
-
- /**
- * Set the items of the listbox in the MessageBox
- * @param items the items to set
- */
- public void setListBoxItems(String[] items) {
- listboxItems = items;
-
- scilabDialogType = X_CHOOSE_TYPE;
- }
-
- /**
- * Get the index of the selected item in the listbox in the MessageBox
- * @return the index
- */
- public int getSelectedItem() {
- return selectedItem;
- }
-
- /**
- * Create the listbox to be displayed in a x_choose dialog
- * @return the scrollpane containing the listbox
- */
- private JScrollPane createXchooseListBox() {
- // Add the ListBox
- listBox = new JList();
- listBox.setLayoutOrientation(JList.VERTICAL);
- listBox.setModel(new DefaultListModel());
- listBox.addMouseListener(new MouseListener() {
-
- public void mouseClicked(MouseEvent arg0) {
- if (arg0.getClickCount() == 2) {
- selectedItem = listBox.getSelectedIndex() + 1;
- // Notify btnOK for not modal Dialogs
- synchronized (btnOK) {
- btnOK.notify();
- }
- dispose();
- }
- }
-
- public void mouseEntered(MouseEvent arg0) {
+ userValue = ""; /* To make getValueSize return a non zero value */
+ } else if (scilabDialogType == X_CHOICES_TYPE) {
+
+ // Get the selected button index of each button group
+ for (int groupNum = 0; groupNum < buttonGroups.length; groupNum++) {
+ Enumeration<AbstractButton> theButtons = buttonGroups[groupNum].getElements();
+ for (int btnNum = 0; btnNum < buttonGroups[groupNum].getButtonCount(); btnNum++) {
+ JToggleButton b = (JToggleButton) theButtons.nextElement();
+ if (b.getModel() == buttonGroups[groupNum].getSelection()) {
+ userSelectedButtons[groupNum] = btnNum + 1;
}
-
- public void mouseExited(MouseEvent arg0) {
- }
-
- public void mousePressed(MouseEvent arg0) {
- }
-
- public void mouseReleased(MouseEvent arg0) {
- }
-
- });
- ((DefaultListModel) listBox.getModel()).clear();
- for (int i = 0; i < listboxItems.length; i++) {
- ((DefaultListModel) listBox.getModel()).addElement(listboxItems[i]);
+ }
}
- listBox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- JScrollPane scrollPane = new JScrollPane(listBox);
- int scrollWidth = (int) Math.min(WINDOW_WIDTH, listBox.getPreferredSize().getWidth() + OFFSET);
- int scrollHeight = LISTBOX_HEIGHT;
- scrollPane.setPreferredSize(new Dimension(scrollWidth, scrollHeight));
- return scrollPane;
+ userValue = ""; /* To make getValueSize return a non zero value */
+ }
+ selectedButton = 1;
+ } else if (ae.getSource() == btnCancel) {
+ selectedButton = 2;
+ } else if (buttonsLabels != null) { // User defined buttons
+ for (int index = 0; index < buttonsLabels.length; index++) {
+ if (((JButton) ae.getSource()).getText().equals(buttonsLabels[index])) {
+ selectedButton = index + 1;
+ break;
+ }
+ }
}
-
- /**
- * Set the name of the lines labels in the editable zone in the MessageBox
- * @param labels the labels
- */
- public void setLineLabels(String[] labels) {
- scilabDialogType = X_MDIALOG_TYPE;
- lineLabels = labels;
+ // Notify btnOK for not modal Dialogs
+ synchronized (btnOK) {
+ btnOK.notify();
}
-
- /**
- * Set the name of the columns labels in the editable zone in the MessageBox
- * @param labels the labels
- */
- public void setColumnLabels(String[] labels) {
- columnLabels = labels;
+ // Destroy the Dialog
+ dispose();
+ }
+ /**
+ * Get the index of the button clicked
+ * @return the index of the button clicked
+ */
+ public int getSelectedButton() {
+ return selectedButton;
+ }
+
+ /**
+ * Set the indices of the default selected buttons (x_choices)
+ * @param indices the indices of the default selected buttons
+ */
+ public void setDefaultSelectedButtons(int[] indices) {
+ defaultSelectedButtons = indices;
+ scilabDialogType = X_CHOICES_TYPE;
+ }
+
+ /**
+ * Get the indices of the selected buttons (x_choices)
+ * @return the indices of the selected buttons
+ */
+ public int[] getUserSelectedButtons() {
+ return userSelectedButtons;
+ }
+
+ /**
+ * Set the labels of the buttons in the MessageBox
+ * @param labels the labels of the buttons
+ */
+ public void setButtonsLabels(String[] labels) {
+ buttonsLabels = labels;
+ }
+
+ /**
+ * Set the initial values of the editable zone in the MessageBox
+ * @param value the initial values
+ */
+ public void setInitialValue(String[] value) {
+ int line = 0;
+ initialValue = "";
+ for (line = 0; line < value.length - 1; line++) {
+ initialValue += value[line] + NEW_LINE;
}
-
- /**
- * Set the default values of a multi-value editable zone in the MessageBox
- * @param values the values
- */
- public void setDefaultInput(String[] values) {
- defaultInput = values;
+ initialValue += value[line];
+ initialValueSize = value.length;
+
+ scilabDialogType = X_DIALOG_TYPE;
+ }
+
+ /**
+ * Get the value of the editable zone in the MessageBox
+ * @return the value
+ */
+ public String[] getValue() {
+ if (scilabDialogType == X_MDIALOG_TYPE) {
+ return userValues;
+ } else {
+ return userValue.split(NEW_LINE);
}
-
- /**
- * Set a MessageBox modal or not
- * @param status true to set the MessageBox modal and false else
- */
- public void setModal(boolean status) {
- modal = status;
+ }
+
+ /**
+ * Get the size of the value of the editable zone in the MessageBox
+ * @return the value size
+ */
+ public int getValueSize() {
+ if (userValue == null) {
+ return 0;
+ } else {
+ return userValue.split(NEW_LINE).length;
}
+ }
+
+ /**
+ * Set the items of the listbox in the MessageBox
+ * @param items the items to set
+ */
+ public void setListBoxItems(String[] items) {
+ listboxItems = items;
+
+ scilabDialogType = X_CHOOSE_TYPE;
+ }
+
+ /**
+ * Get the index of the selected item in the listbox in the MessageBox
+ * @return the index
+ */
+ public int getSelectedItem() {
+ return selectedItem;
+ }
+
+ /**
+ * Create the listbox to be displayed in a x_choose dialog
+ * @return the scrollpane containing the listbox
+ */
+ private JScrollPane createXchooseListBox() {
+ // Add the ListBox
+ listBox = new JList();
+ listBox.setLayoutOrientation(JList.VERTICAL);
+ listBox.setModel(new DefaultListModel());
+ listBox.addMouseListener(new MouseListener() {
+
+ public void mouseClicked(MouseEvent arg0) {
+ if (arg0.getClickCount() == 2) {
+ selectedItem = listBox.getSelectedIndex() + 1;
+ // Notify btnOK for not modal Dialogs
+ synchronized (btnOK) {
+ btnOK.notify();
+ }
+ dispose();
+ }
+ }
-
- /**
- * Set the MessageBox icon
- * @param name the name of the icon
- */
- public void setIcon(String name) {
- if (name.equals("error")) {
- messageType = JOptionPane.ERROR_MESSAGE;
- } else if (name.equals("hourglass")) {
- messageIcon = hourglassIcon;
- } else if (name.equals("info")) {
- messageType = JOptionPane.INFORMATION_MESSAGE;
- } else if (name.equals("passwd")) {
- messageIcon = passwdIcon;
- } else if (name.equals("question")) {
- messageType = JOptionPane.QUESTION_MESSAGE;
- } else if (name.equals("warning")) {
- messageType = JOptionPane.WARNING_MESSAGE;
- } else {
- messageIcon = scilabIcon;
+ public void mouseEntered(MouseEvent arg0) {
}
- }
- private boolean isWindows() {
- return System.getProperty("os.name").toLowerCase().contains("windows");
- }
+ public void mouseExited(MouseEvent arg0) {
+ }
- /**
- * Set the component used to set the location of the MessageBox (default is Scilab Console)
- * @param parent
- */
- public void setParentForLocation(Tab parent) {
- if (parent != null) {
- parentWindow = (Component) parent.getAsSimpleTab();
- } else {
- parentWindow = null;
+ public void mousePressed(MouseEvent arg0) {
}
- }
+ public void mouseReleased(MouseEvent arg0) {
+ }
+ });
+ ((DefaultListModel) listBox.getModel()).clear();
+ for (int i = 0; i < listboxItems.length; i++) {
+ ((DefaultListModel) listBox.getModel()).addElement(listboxItems[i]);
+ }
+ listBox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ JScrollPane scrollPane = new JScrollPane(listBox);
+ int scrollWidth = (int) Math.min(WINDOW_WIDTH, listBox.getPreferredSize().getWidth() + OFFSET);
+ int scrollHeight = LISTBOX_HEIGHT;
+ scrollPane.setPreferredSize(new Dimension(scrollWidth, scrollHeight));
+ return scrollPane;
+ }
+
+ /**
+ * Set the name of the lines labels in the editable zone in the MessageBox
+ * @param labels the labels
+ */
+ public void setLineLabels(String[] labels) {
+ scilabDialogType = X_MDIALOG_TYPE;
+ lineLabels = labels;
+ }
+
+ /**
+ * Set the name of the columns labels in the editable zone in the MessageBox
+ * @param labels the labels
+ */
+ public void setColumnLabels(String[] labels) {
+ columnLabels = labels;
+ }
+
+ /**
+ * Set the default values of a multi-value editable zone in the MessageBox
+ * @param values the values
+ */
+ public void setDefaultInput(String[] values) {
+ defaultInput = values;
+ }
+
+ /**
+ * Set a MessageBox modal or not
+ * @param status true to set the MessageBox modal and false else
+ */
+ public void setModal(boolean status) {
+ modal = status;
+ }
+
+
+ /**
+ * Set the MessageBox icon
+ * @param name the name of the icon
+ */
+ public void setIcon(String name) {
+ if (name.equals("error")) {
+ messageType = JOptionPane.ERROR_MESSAGE;
+ } else if (name.equals("hourglass")) {
+ messageIcon = hourglassIcon;
+ } else if (name.equals("info")) {
+ messageType = JOptionPane.INFORMATION_MESSAGE;
+ } else if (name.equals("passwd")) {
+ messageIcon = passwdIcon;
+ } else if (name.equals("question")) {
+ messageType = JOptionPane.QUESTION_MESSAGE;
+ } else if (name.equals("warning")) {
+ messageType = JOptionPane.WARNING_MESSAGE;
+ } else {
+ messageIcon = scilabIcon;
+ }
+ }
+
+ private boolean isWindows() {
+ return System.getProperty("os.name").toLowerCase().contains("windows");
+ }
+
+ /**
+ * Set the component used to set the location of the MessageBox (default is Scilab Console)
+ * @param parent
+ */
+ public void setParentForLocation(Component parent) {
+ parentWindow = parent;
+ }
+
+ /**
+ * Set the component used to set the location of the MessageBox (default is Scilab Console)
+ * @param parent
+ */
+ public void setParentForLocation(Tab parent) {
+ setParentForLocation((Component) parent.getAsSimpleTab());
+ }
}
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import javax.swing.Action;
import javax.swing.ImageIcon;
import org.flexdock.docking.event.DockingEvent;
import org.flexdock.docking.activation.ActiveDockableTracker;
import org.flexdock.docking.props.PropertyChangeListenerFactory;
+import org.flexdock.view.Titlebar;
import org.flexdock.view.View;
+
import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvasImpl;
import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox;
import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
import org.scilab.modules.gui.radiobutton.RadioButton;
import org.scilab.modules.gui.slider.Slider;
import org.scilab.modules.gui.tab.SimpleTab;
+import org.scilab.modules.gui.tab.Tab;
import org.scilab.modules.gui.textbox.TextBox;
import org.scilab.modules.gui.toolbar.ToolBar;
import org.scilab.modules.gui.tree.Tree;
import org.scilab.modules.gui.utils.SciUndockingAction;
import org.scilab.modules.gui.utils.SciClosingAction;
import org.scilab.modules.gui.utils.Size;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
/**
* Swing implementation for Scilab tabs in GUIs
}
private int parentWindowId;
-
+ private String appNameOnClose;
private MenuBar menuBar;
-
private ToolBar toolBar;
-
private TextBox infoBar;
/** Contains the canvas and widgets */
getTitlebar().addFocusListener(this);
addFocusListener(this);
+ setCallback(null);
+ }
+
+ /**
+ * Create a graphic tab used to display a figure with 3D graphics and/or UIcontrols
+ * @param name name of the tab
+ * @param figureId id of the displayed figure
+ */
+ public SwingScilabTab(String name, int figureId) {
+ super(name, name, name);
+
+ // This button is "overloaded" when we add a callback
+ //this.addAction(DockingConstants.CLOSE_ACTION);
+ // Removed because make JOGL crash when "Unpin"
+ //this.addAction(DockingConstants.PIN_ACTION);
+ this.addAction(DockingConstants.ACTIVE_WINDOW);
+
+ // create the panel in which all the uiobjects will lie.
+ contentPane = new SwingScilabAxes(figureId);
+
+ // add it inside a JSCrollPane
+ scrolling = new SwingScilabScrollPane(contentPane);
+
+ // put in in the back of the tab
+ setContentPane(scrolling.getAsContainer());
+
+ this.setVisible(true);
+
+ getTitlebar().addFocusListener(this);
+ addFocusListener(this);
+ setCallback(null);
}
/**
this(name, name);
}
+ public static void removeActions(SwingScilabTab tab) {
+ tab.setActionBlocked(DockingConstants.CLOSE_ACTION, true);
+ tab.setActionBlocked(UNDOCK, true);
+ tab.getTitlebar().revalidate();
+ }
+
+ public static void addActions(SwingScilabTab tab) {
+ tab.setActionBlocked(DockingConstants.CLOSE_ACTION, false);
+ tab.setActionBlocked(UNDOCK, false);
+ tab.getTitlebar().revalidate();
+ }
+
/**
* @param e the FocusEvent
*/
public void focusGained(FocusEvent e) {
+ //ActiveDockableTracker.requestDockableActivation(this);
if (contentPane != null) {
contentPane.requestFocus();
} else if (getContentPane() != null) {
}
/**
+ * Call when the tab restoration is ended.
+ */
+ public void endedRestoration() { }
+
+ /**
* @return the window icon associated with this tab
*/
public Image getWindowIcon() {
- if (icon ==null) {
+ if (icon == null) {
return SCILAB_ICON;
} else {
return icon;
public void focusLost(FocusEvent e) { }
/**
- * Create a graphic tab used to display a figure with 3D graphics and/or UIcontrols
- * @param name name of the tab
- * @param figureId id of the displayed figure
- */
- public SwingScilabTab(String name, int figureId) {
- super(name, name, name);
-
- // This button is "overloaded" when we add a callback
- //this.addAction(DockingConstants.CLOSE_ACTION);
- // Removed because make JOGL crash when "Unpin"
- //this.addAction(DockingConstants.PIN_ACTION);
- this.addAction(DockingConstants.ACTIVE_WINDOW);
-
- // create the panel in which all the uiobjects will lie.
- contentPane = new SwingScilabAxes(figureId);
-
- // add it inside a JSCrollPane
- scrolling = new SwingScilabScrollPane(contentPane);
-
- // put in in the back of the tab
- setContentPane(scrolling.getAsContainer());
-
- this.setVisible(true);
-
- getTitlebar().addFocusListener(this);
- addFocusListener(this);
- }
-
- /**
* {@inheritDoc}
*/
public void dockingComplete(DockingEvent evt) {
if (port.getDockables().size() > 1) {
while (iter.hasNext()) {
Object d = iter.next();
- if (d instanceof View) {
- View view = (View) d;
- view.setActionBlocked(DockingConstants.CLOSE_ACTION, false);
- view.setActionBlocked(UNDOCK, false);
+ if (d instanceof SwingScilabTab) {
+ SwingScilabTab view = (SwingScilabTab) d;
+ addActions(view);
}
}
} else {
- setActionBlocked(UNDOCK, true);
- setActionBlocked(DockingConstants.CLOSE_ACTION, true);
+ removeActions(this);
}
}
*/
public void setName(String newTabName) {
setTitle(newTabName, true);
-
getTitlePane().repaint();
SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this).setName(newTabName);
}
/**
+ * @return the UUID of the parent window
+ */
+ public String getParentWindowUUID() {
+ return ((SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this)).getUUID();
+ }
+
+ /**
* Gets the title of a swing Scilab tab
* @return the title of the tab
* @see org.scilab.modules.gui.tab.Tab#getTitle()
return contentPane.addWidget(member.getAsComponent());
}
-
/**
* Add a Tree member (dockable element) to container and returns its index
* @param member the member to add
contentPane.removeTree(member);
}
-
-
-
/**
* Add a member (dockable element) to container and returns its index
* @param member the member to add
if (callback != null) {
action = new SciClosingAction(this, callback);
} else {
- this.addAction(DockingConstants.CLOSE_ACTION);
- action = new SciClosingAction(this, this.getTitlebar().getAction(DockingConstants.CLOSE_ACTION));
+ action = new SciClosingAction(this);
}
action.putValue(Action.NAME, DockingConstants.CLOSE_ACTION);
- this.addAction(action);
+ ((Titlebar) getTitlePane()).removeAction(DockingConstants.CLOSE_ACTION);
+ addAction(action);
/* Undock button */
SciUndockingAction undockAction = new SciUndockingAction(this);
undockAction.putValue(Action.NAME, UNDOCK);
- this.addAction(undockAction);
+ ((Titlebar) getTitlePane()).removeAction(UNDOCK);
+ addAction(undockAction);
}
/**
* Close the tab and disable it.
*/
public void close() {
- this.getContentPane().removeAll();
- this.setMenuBar(null);
- this.setToolBar(null);
- this.setInfoBar(null);
- this.setTitlebar(null);
- this.removeAll();
+ getContentPane().removeAll();
+ setMenuBar(null);
+ setToolBar(null);
+ setInfoBar(null);
+ setTitlebar(null);
+ removeAll();
setActive(false);
scrolling = null;
package org.scilab.modules.gui.bridge.window;
import java.awt.Dimension;
+import java.awt.Point;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
+import java.util.UUID;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
+import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import org.flexdock.docking.DockingConstants;
import org.flexdock.docking.DockingManager;
import org.flexdock.docking.DockingPort;
+import org.flexdock.docking.DockingStrategy;
import org.flexdock.docking.activation.ActiveDockableTracker;
import org.flexdock.docking.defaults.DefaultDockingPort;
+import org.flexdock.docking.defaults.DefaultDockingStrategy;
import org.flexdock.view.View;
import org.scilab.modules.action_binding.InterpreterManagement;
import org.scilab.modules.gui.bridge.menubar.SwingScilabMenuBar;
import org.scilab.modules.gui.textbox.TextBox;
import org.scilab.modules.gui.toolbar.SimpleToolBar;
import org.scilab.modules.gui.toolbar.ToolBar;
+import org.scilab.modules.gui.utils.ClosingOperationsManager;
import org.scilab.modules.gui.utils.Position;
import org.scilab.modules.gui.utils.SciDockingListener;
import org.scilab.modules.gui.utils.Size;
import org.scilab.modules.gui.utils.UIElementMapper;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
import org.scilab.modules.gui.window.SimpleWindow;
import org.scilab.modules.renderer.utils.RenderingCapabilities;
*/
public class SwingScilabWindow extends JFrame implements SimpleWindow {
- private static final long serialVersionUID = -5661926417765805660L;
+ private static final long serialVersionUID = -5661926417765805660L;
- private static final int DEFAULTWIDTH = 500;
- private static final int DEFAULTHEIGHT = 500;
+ private static final int DEFAULTWIDTH = 500;
+ private static final int DEFAULTHEIGHT = 500;
- private DefaultDockingPort sciDockingPort;
- private SciDockingListener sciDockingListener;
- private SimpleMenuBar menuBar;
- private SimpleToolBar toolBar;
- private SimpleTextBox infoBar;
+ static {
+ DefaultDockingStrategy.setDefaultResizeWeight(0.5);
+ }
- private int elementId; // the id of the Window which contains this SimpleWindow
- boolean MAC_OS_X = (System.getProperty("os.name").toLowerCase().startsWith("mac os x"));
+ private DefaultDockingPort sciDockingPort;
+ private SciDockingListener sciDockingListener;
+ private SimpleMenuBar menuBar;
+ private SimpleToolBar toolBar;
+ private SimpleTextBox infoBar;
+ private String uuid;
- /**
- * Constructor
- */
- public SwingScilabWindow() {
- super();
+ private int elementId; // the id of the Window which contains this SimpleWindow
+ boolean MAC_OS_X = (System.getProperty("os.name").toLowerCase().startsWith("mac os x"));
- setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ /**
+ * Constructor
+ */
+ public SwingScilabWindow() {
+ super();
- // TODO : Only for testing : Must be removed
- this.setDims(new Size(DEFAULTWIDTH, DEFAULTHEIGHT));
- this.setTitle("Scilab");
- setIconImage(new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/scilab.png").getImage());
+ setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
- /* defining the Layout */
- super.setLayout(new java.awt.BorderLayout());
+ this.uuid = UUID.randomUUID().toString();
- /* Create automatically a docking port associated to the window */
- sciDockingPort = new DefaultDockingPort();
+ // TODO : Only for testing : Must be removed
+ this.setDims(new Size(DEFAULTWIDTH, DEFAULTHEIGHT));
+ this.setTitle("Scilab");
+ setIconImage(new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/scilab.png").getImage());
- //EffectsManager.setPreview(new GhostPreview());
+ /* defining the Layout */
+ super.setLayout(new java.awt.BorderLayout());
- /* The docking port is the center of the Layout of the Window */
- super.add(sciDockingPort, java.awt.BorderLayout.CENTER);
+ /* Create automatically a docking port associated to the window */
+ sciDockingPort = new DefaultDockingPort();
+
+ //EffectsManager.setPreview(new GhostPreview());
- /* there is no menuBar, no toolBar and no infoBar at creation */
- this.menuBar = null;
- this.toolBar = null;
- this.infoBar = null;
+ /* The docking port is the center of the Layout of the Window */
+ super.add(sciDockingPort, java.awt.BorderLayout.CENTER);
- sciDockingListener = new SciDockingListener();
- sciDockingPort.addDockingListener(sciDockingListener);
- /*
- * Prevent the background RootPane to catch Focus.
- * Causes trouble with Scicos use xclick & co.
- */
- this.setFocusable(false);
-
- // let the OS choose the window position if not specified by user.
- setLocationByPlatform(true);
-
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- Object[] dockArray = sciDockingPort.getDockables().toArray();
- for (int i = 0; i < dockArray.length; i++) {
- ((View) dockArray[i]).getActionButton(DockingConstants.CLOSE_ACTION).getAction().actionPerformed(null);
- }
-
- //if dock stay open, do not close main window
- if(dockArray.length == 0){
- removeWindowListener(this);
- }
- }
- });
+ /* there is no menuBar, no toolBar and no infoBar at creation */
+ this.menuBar = null;
+ this.toolBar = null;
+ this.infoBar = null;
- if (MAC_OS_X) {
- registerForMacOSXEvents();
+ sciDockingListener = new SciDockingListener();
+ sciDockingPort.addDockingListener(sciDockingListener);
+ /*
+ * Prevent the background RootPane to catch Focus.
+ * Causes trouble with Scicos use xclick & co.
+ */
+ this.setFocusable(false);
+
+ // let the OS choose the window position if not specified by user.
+ setLocationByPlatform(true);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ ClosingOperationsManager.startClosingOperation(SwingScilabWindow.this);
}
+ });
+
+ if (MAC_OS_X) {
+ registerForMacOSXEvents();
}
+ }
/**
* This method registers some methods against the specific Mac OS X API
* (in order to set the "special" mac os x menus)
*/
private void registerForMacOSXEvents() {
- try {
- // Generate and register the OSXAdapter, passing it a hash of all the methods we wish to
- // use as delegates for various com.apple.eawt.ApplicationListener methods
- OSXAdapter.setAboutHandler(this, getClass().getDeclaredMethod("OSXabout", (Class[])null));
- OSXAdapter.setQuitHandler(this, getClass().getDeclaredMethod("OSXquit", (Class[])null));
- OSXAdapter.setDockIcon(System.getenv("SCI") + "/icons/puffin.png");
- } catch (java.lang.NoSuchMethodException e) {
- System.err.println("OSXAdapter could not find the method: "+e.getLocalizedMessage());
- }
+ try {
+ // Generate and register the OSXAdapter, passing it a hash of all the methods we wish to
+ // use as delegates for various com.apple.eawt.ApplicationListener methods
+ OSXAdapter.setAboutHandler(this, getClass().getDeclaredMethod("OSXabout", (Class[])null));
+ OSXAdapter.setQuitHandler(this, getClass().getDeclaredMethod("OSXquit", (Class[])null));
+ OSXAdapter.setDockIcon(System.getenv("SCI") + "/icons/puffin.png");
+ } catch (java.lang.NoSuchMethodException e) {
+ System.err.println("OSXAdapter could not find the method: "+e.getLocalizedMessage());
+ }
}
/**
InterpreterManagement.requestScilabExec("exit()");
}
+ /**
+ * @return the UUID associated with this window
+ */
+ public String getUUID() {
+ return uuid;
+ }
+ /**
+ * @param uuid the UUID associated with this window
+ */
+ public void setUUID(String uuid) {
+ this.uuid = uuid;
+ }
- /**
- * Creates a swing Scilab window
- * @return the created window
- */
- public static SimpleWindow createWindow() {
- return new SwingScilabWindow();
- }
-
- /**
- * Draws a swing Scilab window
- * @see org.scilab.modules.gui.UIElement#draw()
- */
- public void draw() {
- this.setVisible(true);
- this.doLayout();
- }
+ /**
+ * Creates a swing Scilab window
+ * @return the created window
+ */
+ public static SimpleWindow createWindow() {
+ return new SwingScilabWindow();
+ }
- /**
- * Deiconify the window and put it in front of other window
- */
- public void raise() {
- // blocking call. So graphic synchronization must be desactivated here.
- try {
- SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- // force visibility
- setVisible(true);
-
- // deiconify the window if needed
- setState(NORMAL);
-
- // put it in front of others
- toFront();
- }
- });
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
+ /**
+ * Draws a swing Scilab window
+ * @see org.scilab.modules.gui.UIElement#draw()
+ */
+ public void draw() {
+ this.setVisible(true);
+ this.doLayout();
+ }
+ /**
+ * Deiconify the window and put it in front of other window
+ */
+ public void raise() {
+ // blocking call. So graphic synchronization must be desactivated here.
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ // force visibility
+ setVisible(true);
+
+ // deiconify the window if needed
+ setState(NORMAL);
+
+ // put it in front of others
+ toFront();
+ }
+ });
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
}
- /**
- * Gets the dimensions (width and height) of a swing Scilab window
- * @return the dimensions of the window
- * @see org.scilab.modules.gui.UIElement#getDims()
- */
- public Size getDims() {
- return new Size(getSize().width, getSize().height);
- }
+ }
- /**
- * Sets the dimensions (width and height) of a swing Scilab window
- * @param newWindowSize the dimensions to set to the window
- * @see org.scilab.modules.gui.UIElement#setDims(org.scilab.modules.gui.utils.Size)
- */
- public void setDims(Size newWindowSize) {
+ /**
+ * Gets the dimensions (width and height) of a swing Scilab window
+ * @return the dimensions of the window
+ * @see org.scilab.modules.gui.UIElement#getDims()
+ */
+ public Size getDims() {
+ return new Size(getSize().width, getSize().height);
+ }
- // get the greatest size we can use
- int[] maxSize = RenderingCapabilities.getMaxWindowSize();
+ /**
+ * Sets the dimensions (width and height) of a swing Scilab window
+ * @param newWindowSize the dimensions to set to the window
+ * @see org.scilab.modules.gui.UIElement#setDims(org.scilab.modules.gui.utils.Size)
+ */
+ public void setDims(Size newWindowSize) {
- // make suze size is not greater than the max size
- Dimension finalDim = new Dimension(Math.min(newWindowSize.getWidth(), maxSize[0]),
- Math.min(newWindowSize.getHeight(), maxSize[1]));
+ // get the greatest size we can use
+ int[] maxSize = RenderingCapabilities.getMaxWindowSize();
- setSize(finalDim);
- // validate so the new values are taken into account immediately
- validate();
- }
+ // make suze size is not greater than the max size
+ Dimension finalDim = new Dimension(Math.min(newWindowSize.getWidth(), maxSize[0]),
+ Math.min(newWindowSize.getHeight(), maxSize[1]));
- /**
- * Gets the position (X-coordinate and Y-coordinate) of a swing Scilab window
- * @return the position of the window
- * @see org.scilab.modules.gui.UIElement#getPosition()
- */
- public Position getPosition() {
- return new Position(this.getX(), this.getY());
- }
+ setSize(finalDim);
+ // validate so the new values are taken into account immediately
+ validate();
+ }
- /**
- * Sets the position (X-coordinate and Y-coordinate) of a swing Scilab window
- * @param newWindowPosition the position to set to the window
- * @see org.scilab.modules.gui.UIElement#setPosition(org.scilab.modules.gui.utils.Position)
- */
- public void setPosition(Position newWindowPosition) {
- this.setLocation(newWindowPosition.getX(), newWindowPosition.getY());
- }
+ /**
+ * Gets the position (X-coordinate and Y-coordinate) of a swing Scilab window
+ * @return the position of the window
+ * @see org.scilab.modules.gui.UIElement#getPosition()
+ */
+ public Position getPosition() {
+ return new Position(this.getX(), this.getY());
+ }
- /**
- * Gets the title of a swing Scilab window
- * @return the title of the window
- * @see java.awt.Frame#getTitle(java.lang.String)
- */
- public String getTitle() {
- return super.getTitle();
- }
+ /**
+ * Sets the position (X-coordinate and Y-coordinate) of a swing Scilab window
+ * @param newWindowPosition the position to set to the window
+ * @see org.scilab.modules.gui.UIElement#setPosition(org.scilab.modules.gui.utils.Position)
+ */
+ public void setPosition(Position newWindowPosition) {
+ this.setLocation(newWindowPosition.getX(), newWindowPosition.getY());
+ }
- /**
- * Sets the title of a swing Scilab window
- * @param newWindowTitle the title to set to the window
- * @see java.awt.Frame#setTitle(java.lang.String)
- */
- public void setTitle(String newWindowTitle) {
- // set only if required
- if (newWindowTitle != null && !newWindowTitle.equals(getTitle())) {
- super.setTitle(newWindowTitle);
- }
- }
+ /**
+ * Gets the title of a swing Scilab window
+ * @return the title of the window
+ * @see java.awt.Frame#getTitle(java.lang.String)
+ */
+ public String getTitle() {
+ return super.getTitle();
+ }
- /**
- * {@inheritedDoc}
- */
- public void setName(String name) {
- super.setName(name);
- setTitle(name);
+ /**
+ * Sets the title of a swing Scilab window
+ * @param newWindowTitle the title to set to the window
+ * @see java.awt.Frame#setTitle(java.lang.String)
+ */
+ public void setTitle(String newWindowTitle) {
+ // set only if required
+ if (newWindowTitle != null && !newWindowTitle.equals(getTitle())) {
+ super.setTitle(newWindowTitle);
}
+ }
- /**
- * Gets the docking port associated to the window (created by default at window creation)
- * @return the docking port associated to the window
- */
- public DockingPort getDockingPort() {
- //return (DockingPort) centerFrame.getContentPane();
- return (DockingPort) sciDockingPort;
- }
+ /**
+ * {@inheritedDoc}
+ */
+ public void setName(String name) {
+ super.setName(name);
+ setTitle(name);
+ }
- /**
- * Add a Scilab tab to a Scilab window
- * @param newTab the Scilab tab to add to the Scilab window
- * @see org.scilab.modules.gui.window.Window#addTab(org.scilab.modules.gui.tab.Tab)
- */
- public void addTab(Tab newTab) {
- final SwingScilabTab tabImpl = ((SwingScilabTab) newTab.getAsSimpleTab());
+ /**
+ * Gets the docking port associated to the window (created by default at window creation)
+ * @return the docking port associated to the window
+ */
+ public DockingPort getDockingPort() {
+ //return (DockingPort) centerFrame.getContentPane();
+ return (DockingPort) sciDockingPort;
+ }
- tabImpl.setParentWindowId(this.elementId);
- DockingManager.dock(tabImpl, this.getDockingPort());
- ActiveDockableTracker.requestDockableActivation(tabImpl);
- }
+ /**
+ * Add a Scilab tab to a Scilab window
+ * @param newTab the Scilab tab to add to the Scilab window
+ * @see org.scilab.modules.gui.window.Window#addTab(org.scilab.modules.gui.tab.Tab)
+ */
+ public void addTab(Tab newTab) {
+ final SwingScilabTab tabImpl = ((SwingScilabTab) newTab.getAsSimpleTab());
- /**
- * Remove a Scilab tab from a Scilab window
- * @param tab the Scilab tab to remove from the Scilab window
- * @see org.scilab.modules.gui.window.Window#removeTab(org.scilab.modules.gui.tab.Tab)
- */
- public void removeTab(Tab tab) {
- DockingManager.close(((SwingScilabTab) tab.getAsSimpleTab()));
- DockingManager.unregisterDockable((Dockable) ((SwingScilabTab) tab.getAsSimpleTab()));
- ((SwingScilabTab) tab.getAsSimpleTab()).close();
- if (getDockingPort().getDockables().isEmpty()) {
- // remove xxxBars
- if (toolBar != null) {
- ((SwingScilabToolBar) toolBar).close();
- }
- if (menuBar != null) {
- UIElementMapper.removeMapping(menuBar.getElementId());
- }
- UIElementMapper.removeMapping(this.elementId);
-
- // clean all
- this.removeAll();
- this.dispose();
-
- // disable docking port
- ActiveDockableTracker.getTracker(this).setActive(null);
- sciDockingPort.removeDockingListener(sciDockingListener);
- sciDockingPort = null;
- sciDockingListener = null;
- } else {
- /* Make sur a Tab is active */
- Set<SwingScilabTab> docks = sciDockingPort.getDockables();
- Iterator<SwingScilabTab> it = docks.iterator();
- ActiveDockableTracker.requestDockableActivation((SwingScilabTab) it.next());
- }
- }
+ tabImpl.setParentWindowId(this.elementId);
+ DockingManager.dock(tabImpl, this.getDockingPort());
+ ActiveDockableTracker.requestDockableActivation(tabImpl);
+ }
+ /**
+ * Remove a Scilab tab from a Scilab window
+ * @param tab the Scilab tab to remove from the Scilab window
+ * @see org.scilab.modules.gui.window.Window#removeTab(org.scilab.modules.gui.tab.Tab)
+ */
+ public void removeTabs(SwingScilabTab[] tabs) {
+ for (SwingScilabTab tab : tabs) {
+ DockingManager.unregisterDockable((Dockable) tab);
+ DockingManager.close(tab);
+ tab.close();
+ }
+ if (getDockingPort().getDockables().isEmpty()) {
+ // remove xxxBars
+ if (toolBar != null) {
+ ((SwingScilabToolBar) toolBar).close();
+ }
+ if (menuBar != null) {
+ UIElementMapper.removeMapping(menuBar.getElementId());
+ }
+ UIElementMapper.removeMapping(this.elementId);
+
+ // clean all
+ this.removeAll();
+ this.dispose();
+
+ // disable docking port
+ ActiveDockableTracker.getTracker(this).setActive(null);
+ sciDockingPort.removeDockingListener(sciDockingListener);
+ sciDockingPort = null;
+ sciDockingListener = null;
+ } else {
+ /* Make sur a Tab is active */
+ Set<SwingScilabTab> docks = sciDockingPort.getDockables();
+ Iterator<SwingScilabTab> it = docks.iterator();
+ ActiveDockableTracker.requestDockableActivation((SwingScilabTab) it.next());
+ }
+ }
+ /**
+ * Remove a Scilab tab from a Scilab window
+ * @param tab the Scilab tab to remove from the Scilab window
+ * @see org.scilab.modules.gui.window.Window#removeTab(org.scilab.modules.gui.tab.Tab)
+ */
+ public void removeTab(Tab tab) {
+ removeTabs(new SwingScilabTab[]{(SwingScilabTab) tab.getAsSimpleTab()});
+ }
- /**
- * Sets a Scilab MenuBar to a Scilab window
- * @param newMenuBar the Scilab MenuBar to add to the Scilab window
- * @see org.scilab.modules.gui.window.Window#setMenuBar(org.scilab.modules.gui.menubar.MenuBar)
- */
- public void addMenuBar(MenuBar newMenuBar) {
-
- if (newMenuBar == null) {
- if (this.menuBar != null) {
- this.menuBar = null;
- super.setJMenuBar(null);
- this.repaint();
- }
- // else nothing to do both are null
- } else {
- if (this.menuBar != newMenuBar.getAsSimpleMenuBar()) {
- this.menuBar = newMenuBar.getAsSimpleMenuBar();
- super.setJMenuBar((SwingScilabMenuBar) newMenuBar.getAsSimpleMenuBar());
- this.repaint();
- }
- // else nothing to do element alredy set
- }
+ /**
+ * Sets a Scilab MenuBar to a Scilab window
+ * @param newMenuBar the Scilab MenuBar to add to the Scilab window
+ * @see org.scilab.modules.gui.window.Window#setMenuBar(org.scilab.modules.gui.menubar.MenuBar)
+ */
+ public void addMenuBar(MenuBar newMenuBar) {
+ if (newMenuBar == null) {
+ if (this.menuBar != null) {
+ this.menuBar = null;
+ super.setJMenuBar(null);
+ this.repaint();
+ }
+ // else nothing to do both are null
+ } else {
+ if (this.menuBar != newMenuBar.getAsSimpleMenuBar()) {
+ this.menuBar = newMenuBar.getAsSimpleMenuBar();
+ super.setJMenuBar((SwingScilabMenuBar) newMenuBar.getAsSimpleMenuBar());
+ this.repaint();
+ }
+ // else nothing to do element alredy set
}
+ }
- /**
- * Sets a Scilab ToolBar to a Scilab window
- * @param newToolBar the Scilab ToolBar to set to the Scilab window
- * @see org.scilab.modules.gui.window.Window#setToolBar(org.scilab.modules.gui.toolbar.ToolBar)
- */
- public void addToolBar(ToolBar newToolBar) {
-
- if (newToolBar == null) {
- if (this.toolBar != null) {
- // Remove old InfoBar if already set
- super.remove((SwingScilabToolBar) this.toolBar);
- this.toolBar = null;
- this.repaint();
- }
- // else nothing to do both are null
- } else {
- if (this.toolBar != newToolBar.getAsSimpleToolBar()) {
- if (this.toolBar != null) {
- // Remove old InfoBar if already set
- super.remove((SwingScilabToolBar) this.toolBar);
- }
- this.toolBar = newToolBar.getAsSimpleToolBar();
- super.add((SwingScilabToolBar) this.toolBar, java.awt.BorderLayout.PAGE_START);
- this.repaint();
- }
- // else nothing to do element alredy set
+ /**
+ * Sets a Scilab ToolBar to a Scilab window
+ * @param newToolBar the Scilab ToolBar to set to the Scilab window
+ * @see org.scilab.modules.gui.window.Window#setToolBar(org.scilab.modules.gui.toolbar.ToolBar)
+ */
+ public void addToolBar(ToolBar newToolBar) {
+ if (newToolBar == null) {
+ if (this.toolBar != null) {
+ // Remove old InfoBar if already set
+ super.remove((SwingScilabToolBar) this.toolBar);
+ this.toolBar = null;
+ this.repaint();
+ }
+ // else nothing to do both are null
+ } else {
+ if (this.toolBar != newToolBar.getAsSimpleToolBar()) {
+ if (this.toolBar != null) {
+ // Remove old InfoBar if already set
+ super.remove((SwingScilabToolBar) this.toolBar);
}
+ this.toolBar = newToolBar.getAsSimpleToolBar();
+ super.add((SwingScilabToolBar) this.toolBar, java.awt.BorderLayout.PAGE_START);
+ this.repaint();
+ }
+ // else nothing to do element alredy set
}
+ }
- /**
- * Sets a Scilab InfoBar to a Scilab window
- * @param newInfoBar the Scilab InfoBar to set to the Scilab window
- * @see org.scilab.modules.gui.window.Window#setInfoBar(org.scilab.modules.gui.textbox.TextBox)
- */
- public void addInfoBar(TextBox newInfoBar) {
-
- if (newInfoBar == null) {
- if (this.infoBar != null) {
- // Remove old InfoBar if already set
- super.remove((SwingScilabTextBox) this.infoBar);
- this.infoBar = null;
- this.repaint();
- }
- // else nothing to do both are null
- } else {
- if (this.infoBar != newInfoBar.getAsSimpleTextBox()) {
- if (this.infoBar != null) {
- // Remove old InfoBar if already set
- super.remove((SwingScilabTextBox) this.infoBar);
- }
- this.infoBar = newInfoBar.getAsSimpleTextBox();
- super.add((SwingScilabTextBox) this.infoBar, java.awt.BorderLayout.PAGE_END);
- this.repaint();
- }
- // else nothing to do element alredy set
+ /**
+ * Sets a Scilab InfoBar to a Scilab window
+ * @param newInfoBar the Scilab InfoBar to set to the Scilab window
+ * @see org.scilab.modules.gui.window.Window#setInfoBar(org.scilab.modules.gui.textbox.TextBox)
+ */
+ public void addInfoBar(TextBox newInfoBar) {
+ if (newInfoBar == null) {
+ if (this.infoBar != null) {
+ // Remove old InfoBar if already set
+ super.remove((SwingScilabTextBox) this.infoBar);
+ this.infoBar = null;
+ this.repaint();
+ }
+ // else nothing to do both are null
+ } else {
+ if (this.infoBar != newInfoBar.getAsSimpleTextBox()) {
+ if (this.infoBar != null) {
+ // Remove old InfoBar if already set
+ super.remove((SwingScilabTextBox) this.infoBar);
}
+ this.infoBar = newInfoBar.getAsSimpleTextBox();
+ super.add((SwingScilabTextBox) this.infoBar, java.awt.BorderLayout.PAGE_END);
+ this.repaint();
+ }
+ // else nothing to do element alredy set
}
+ }
- /**
- * Get the element id for this window
- * @return id the id of the corresponding window object
- */
- public int getElementId() {
- return elementId;
- }
+ /**
+ * Get the element id for this window
+ * @return id the id of the corresponding window object
+ */
+ public int getElementId() {
+ return elementId;
+ }
- /**
- * Set the element id for this window
- * @param id the id of the corresponding window object
- */
- public void setElementId(int id) {
- this.elementId = id;
- sciDockingListener.setAssociatedWindowId(id);
- }
+ /**
+ * Set the element id for this window
+ * @param id the id of the corresponding window object
+ */
+ public void setElementId(int id) {
+ this.elementId = id;
+ sciDockingListener.setAssociatedWindowId(id);
+ }
- /**
- * Close the window
- * @see org.scilab.modules.gui.window.SimpleWindow#close()
- */
- public void close() {
- dispose();
- }
+ /**
+ * Close the window
+ * @see org.scilab.modules.gui.window.SimpleWindow#close()
+ */
+ public void close() {
+ dispose();
+ }
- /**
- * @return number of objects (tabs) docked in this window
- */
- public int getNbDockedObjects() {
- return sciDockingListener.getNbDockedObjects();
- }
+ /**
+ * @return number of objects (tabs) docked in this window
+ */
+ public int getNbDockedObjects() {
+ return sciDockingPort.getDockables().size();
+ }
- /**
- * Update the dimension of the window and its component.
- * Only useful when the window is not yet visible
- */
- public void updateDimensions() {
- pack();
- }
+ /**
+ * Update the dimension of the window and its component.
+ * Only useful when the window is not yet visible
+ */
+ public void updateDimensions() {
+ pack();
+ }
- /**
- * DeIconify Window
- */
- public void windowDeiconified() {
- super.setState(Frame.NORMAL);
- }
+ /**
+ * DeIconify Window
+ */
+ public void windowDeiconified() {
+ super.setState(Frame.NORMAL);
+ }
- /**
- * Iconify Window
- */
- public void windowIconified() {
- super.setState(Frame.ICONIFIED);
- }
+ /**
+ * Iconify Window
+ */
+ public void windowIconified() {
+ super.setState(Frame.ICONIFIED);
+ }
- /**
- * Maximized Window
- */
- public void windowMaximized() {
- super.setExtendedState(Frame.MAXIMIZED_BOTH);
- }
+ /**
+ * Maximized Window
+ */
+ public void windowMaximized() {
+ super.setExtendedState(Frame.MAXIMIZED_BOTH);
+ }
- /**
- * Window is in the "normal" state.
- */
- public void windowNormal() {
- super.setState(Frame.NORMAL);
- }
+ /**
+ * Window is in the "normal" state.
+ */
+ public void windowNormal() {
+ super.setState(Frame.NORMAL);
+ }
+
+ public void saveState() {
+ WindowsConfigurationManager.saveWindowProperties(this);
+ }
}
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2008 - INRIA - Vincent Couvert
+ * Copyright (C) 2011 - 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
import javax.swing.SwingUtilities;
import org.scilab.modules.commons.ScilabConstants;
+import org.scilab.modules.commons.gui.ScilabGUIUtilities;
import org.scilab.modules.gui.bridge.ScilabBridge;
import org.scilab.modules.gui.bridge.helpbrowser.SwingScilabHelpBrowser;
import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
import org.scilab.modules.gui.menubar.MenuBar;
import org.scilab.modules.gui.tab.ScilabTab;
import org.scilab.modules.gui.tab.Tab;
+import org.scilab.modules.gui.tabfactory.HelpBrowserTab;
+import org.scilab.modules.gui.tabfactory.HelpBrowserTabFactory;
+import org.scilab.modules.gui.tabfactory.ScilabTabFactory;
import org.scilab.modules.gui.textbox.ScilabTextBox;
import org.scilab.modules.gui.textbox.TextBox;
import org.scilab.modules.gui.utils.ConfigManager;
import org.scilab.modules.gui.utils.MenuBarBuilder;
import org.scilab.modules.gui.utils.Position;
import org.scilab.modules.gui.utils.Size;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
import org.scilab.modules.gui.window.ScilabWindow;
import org.scilab.modules.gui.window.Window;
import org.scilab.modules.localization.Messages;
/**
* Class for Scilab Help Browser in GUIs
* @author Vincent COUVERT
+ * @author Calixte DENIZET
*/
public class ScilabHelpBrowser extends ScilabDockable implements HelpBrowser {
+ public static final String HELPUUID = "d1ef5062-533e-4aee-b12a-66740820d6d1";
+
private static final String SCI = ScilabConstants.SCI.getPath();
private static final String MENUBARXMLFILE = SCI + "/modules/gui/etc/helpbrowser_menubar.xml";
private static final boolean isMac = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1;
private static HelpBrowser instance;
-
private static Tab helpTab;
+ private static String language;
+ private static String[] helps;
+
+ static {
+ ScilabTabFactory.getInstance().addTabFactory(HelpBrowserTabFactory.getInstance());
+ }
+
private SimpleHelpBrowser component;
+ private Window parentWindow;
/**
* Constructor
}
/**
+ * Creates a SwingScilabTab containing the help browser
+ * @return the corresponding SwingScilabTab
+ */
+ public static SwingScilabTab createHelpBrowserTab() {
+ helpTab = ScilabTab.createTab(Messages.gettext("Help Browser"), HELPUUID);
+ String url = restoreHelpBrowserState();
+
+ instance = new ScilabHelpBrowser(helps, language);
+ helpTab.addMember(instance);
+
+ MenuBar menubar = MenuBarBuilder.buildMenuBar(MENUBARXMLFILE);
+ helpTab.addMenuBar(menubar);
+
+ TextBox infobar = ScilabTextBox.createTextBox();
+ helpTab.addInfoBar(infobar);
+
+ KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
+ manager.addKeyEventDispatcher(new KeyEventDispatcher() {
+ // This is a workaround for Mac OS X where e.getKeyCode() sometimes returns a bad value
+ public boolean dispatchKeyEvent(KeyEvent e) {
+ if (e.getID() == KeyEvent.KEY_PRESSED) {
+ Container c = SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, (SwingScilabTab) helpTab.getAsSimpleTab());
+ if (e.getSource() instanceof Component) {
+ Container cs = SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, (Component) e.getSource());
+ char chr = e.getKeyChar();
+
+ if (cs == c && ((chr == '-' || chr == '_' || chr == '=' || chr == '+')
+ && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0)) {
+ if (chr == '-' || chr == '_') {
+ ((SwingScilabHelpBrowser) ((ScilabHelpBrowser) instance).component).decreaseFont();
+ } else {
+ ((SwingScilabHelpBrowser) ((ScilabHelpBrowser) instance).component).increaseFont();
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ });
+
+ SwingScilabHelpBrowser browser = (SwingScilabHelpBrowser) ((ScilabHelpBrowser) instance).component;
+ browser.setCurrentURL(url);
+
+ return (SwingScilabTab) helpTab.getAsSimpleTab();
+ }
+
+ /**
* Creates a Scilab Help Browser
* @param helps help chapters and directories
* @param language Scilab current language
*/
public static HelpBrowser createHelpBrowser(String[] helps, String language) {
if (instance == null) {
-
- instance = new ScilabHelpBrowser(helps, language);
+ ScilabHelpBrowser.language = language;
+ ScilabHelpBrowser.helps = helps;
+ boolean success = WindowsConfigurationManager.restoreUUID(HELPUUID);
+ if (!success) {
+ HelpBrowserTabFactory.getInstance().getTab(HELPUUID);
+ ((ScilabHelpBrowser) instance).setParentWindow();
+ ((ScilabHelpBrowser) instance).parentWindow.addTab(helpTab);
+ ((ScilabHelpBrowser) instance).parentWindow.setVisible(true);
+ }
if (ScilabConsole.isExistingConsole() && ScilabConsole.getConsole().getInfoBar() != null) {
if (ScilabConsole.getConsole().getInfoBar().getText().equals(Messages.gettext("Loading help browser..."))) {
return null;
}
}
-
- helpTab = ScilabTab.createTab(Messages.gettext("Help Browser"));
- helpTab.addMember(instance);
- /* Action when the Browser tab is closed */
- helpTab.setCallback(ScilabCallBack
- .createCallback("org.scilab.modules.gui.bridge.CallScilabBridge.closeHelpBrowser", ScilabCallBack.JAVA_OUT_OF_XCLICK_AND_XGETMOUSE));
-
- MenuBar menubar = MenuBarBuilder.buildMenuBar(MENUBARXMLFILE);
- helpTab.addMenuBar(menubar);
-
- TextBox infobar = ScilabTextBox.createTextBox();
- helpTab.addInfoBar(infobar);
-
- Window helpWindow = ScilabWindow.createWindow();
- helpWindow.addTab(helpTab);
-
- KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
- manager.addKeyEventDispatcher(new KeyEventDispatcher() {
- // This is a workaround for Mac OS X where e.getKeyCode() sometimes returns a bad value
- public boolean dispatchKeyEvent(KeyEvent e) {
- if (e.getID() == KeyEvent.KEY_PRESSED) {
- Container c = SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, (SwingScilabTab) helpTab.getAsSimpleTab());
- if (e.getSource() instanceof Component) {
- Container cs = SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, (Component) e.getSource());
- char chr = e.getKeyChar();
-
- if (cs == c && ((chr == '-' || chr == '_' || chr == '=' || chr == '+')
- && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0)) {
- if (chr == '-' || chr == '_') {
- ((SwingScilabHelpBrowser) ((ScilabHelpBrowser) instance).component).decreaseFont();
- } else {
- ((SwingScilabHelpBrowser) ((ScilabHelpBrowser) instance).component).increaseFont();
- }
- return true;
- }
- }
- }
- return false;
- }
- });
-
- /* Set the dimension / position of the help window */
- helpWindow.setPosition(ConfigManager.getHelpWindowPosition());
- helpWindow.setDims(ConfigManager.getHelpWindowSize());
-
- helpWindow.draw();
- } else {
- SwingScilabWindow window = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, (SwingScilabTab) helpTab.getAsSimpleTab());
- window.setVisible(true);
- window.toFront();
}
+ SwingScilabWindow window = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, (SwingScilabTab) helpTab.getAsSimpleTab());
+ ScilabGUIUtilities.toFront(window);
+
return instance;
}
/**
+ * Set a default parent window
+ */
+ public void setParentWindow() {
+ this.parentWindow = ScilabWindow.createWindow();
+ SwingScilabWindow window = (SwingScilabWindow) parentWindow.getAsSimpleWindow();
+ window.setLocation(0, 0);
+ window.setSize(500, 500);
+ }
+
+ /**
* Display the home page
*/
public static void startHomePage() {
}
/**
+ * @return the current displayed url as String
+ */
+ public String getCurrentURL() {
+ SwingScilabHelpBrowser browser = (SwingScilabHelpBrowser) ((ScilabHelpBrowser) instance).component;
+ return browser.getCurrentURL();
+ }
+
+ /**
* Increase the font of the help viewer
*/
public void increaseFont() {
ScilabBridge.fullTextSearch(this, keyword);
}
+ public static void closeHelpBrowser() {
+ instance.close();
+ }
+
/**
* Close the HelpBrowser
*/
public void close() {
- ScilabBridge.close(this);
- helpTab.close();
+ saveHelpBrowserState();
instance = null;
}
public TextBox getInfoBar() {
return helpTab.getInfoBar();
}
+
+
+ /**
+ * Save the state of this help browser
+ */
+ public void saveHelpBrowserState() {
+ ConfigManager.saveHelpBrowserState(getCurrentURL());
+ }
+
+ /**
+ * Restore the state of this help browser
+ * @return the last id displayed in the browser
+ */
+ public static String restoreHelpBrowserState() {
+ return ConfigManager.getHelpBrowserState();
+ }
}
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2009 - DIGITEO - Antoine ELIAS
- *
+ *
* 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
+ * are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
*
*/
package org.scilab.modules.gui.messagebox;
+import java.awt.Component;
+
+import org.scilab.modules.gui.bridge.messagebox.SwingScilabMessageBox;
import org.scilab.modules.gui.tab.Tab;
import org.scilab.modules.localization.Messages;
*/
public final class ScilabModalDialog {
- /**
- * Message box button type
- */
- public enum ButtonType {
- OK,
- OK_CANCEL,
- YES_NO,
- YES_NO_CANCEL,
- CANCEL_OR_SAVE_AND_EXECUTE
- }
-
- /**
- * Message box button type
- */
-
- public enum IconType {
- ERROR_ICON,
- INFORMATION_ICON,
- PASSWORD_ICON,
- QUESTION_ICON,
- WARNING_ICON,
- SCILAB_ICON
- }
-
- public enum AnswerOption {
- OK_OPTION,
- CANCEL_OPTION,
- YES_OPTION,
- NO_OPTION,
- SAVE_EXECUTE_OPTION
- }
- /**
- * private constructor, only static functions
- */
- private ScilabModalDialog() {
- }
-
-
- /**
- * @param messages : messages to display
- * @param parent : tab to be used to set the location of the messagebox
- * @param title : title of the message box
- * default icon "scilab"
- * default button "OK"
- * @return index of the selected button
- */
- public static AnswerOption show(Tab parent, String[] messages) {
- return show(parent, messages, Messages.gettext("Scilab Message"), IconType.SCILAB_ICON, ButtonType.OK);
- }
-
- /**
- * @param message : message to display
- * @param parent : tab to be used to set the location of the messagebox
- * @param title : title of the message box
- * default icon "scilab"
- * default button "OK"
- * @return index of the selected button
- */
- public static AnswerOption show(Tab parent, String message) {
- return show(parent, new String[]{message}, Messages.gettext("Scilab Message"), IconType.SCILAB_ICON, ButtonType.OK);
- }
-
- /**
- * @param messages : messages to display
- * @param parent : tab to be used to set the location of the messagebox
- * @param title : title of the message box
- * default icon "Warning"
- * default button "OK"
- * @return index of the selected button
- */
- public static AnswerOption show(Tab parent, String[] messages, String title) {
- return show(parent, messages, title, IconType.SCILAB_ICON, ButtonType.OK);
- }
-
- /**
- * @param message : message to display
- * @param parent : tab to be used to set the location of the messagebox
- * @param title : title of the message box
- * default icon "Warning"
- * default button "OK"
- * @return index of the selected button
- */
- public static AnswerOption show(Tab parent, String message, String title) {
- return show(parent, new String[]{message}, title, IconType.SCILAB_ICON, ButtonType.OK);
- }
-
- /**
- * @param messages : messages to display
- * @param parent : tab to be used to set the location of the messagebox
- * @param title : title of the message box
- * @param iconType : message box icon ( see IconType )
- * @return index of the selected button
- */
- public static AnswerOption show(Tab parent, String[] messages, String title, ScilabModalDialog.IconType iconType) {
- return show(parent, messages, title, iconType, ButtonType.OK);
- }
-
- /**
- * @param message : message to display
- * @param parent : tab to be used to set the location of the messagebox
- * @param title : title of the message box
- * @param iconType : message box icon ( see IconType )
- * @return index of the selected button
- */
- public static AnswerOption show(Tab parent, String message, String title, ScilabModalDialog.IconType iconType) {
- return show(parent, new String[]{message}, title, iconType, ButtonType.OK);
- }
-
- /**
- * @param message : message to display
- * @param parent : tab to be used to set the location of the messagebox
- * @param title : title of the message box
- * @param iconType : message box icon ( see IconType )
- * @param buttonType : message box type ( see ButtonType )
- * @return index of the selected button
- */
- public static AnswerOption show(Tab parent, String message, String title,
- ScilabModalDialog.IconType iconType, ScilabModalDialog.ButtonType buttonType) {
- return show(parent, new String[]{message}, title, iconType, buttonType);
- }
-
- /**
- * @param messages : messages to display
- * @param parent : tab to be used to set the location of the messagebox
- * @param title : title of the message box
- * @param iconType : message box icon ( see IconType )
- * @param buttonType : message box type ( see ButtonType )
- * @return index of the selected button
- */
- public static AnswerOption show(Tab parent, String[] messages, String title,
- ScilabModalDialog.IconType iconType, ScilabModalDialog.ButtonType buttonType) {
-
-
- MessageBox messageBox = ScilabMessageBox.createMessageBox();
- messageBox.setTitle(title);
- messageBox.setMessage(messages);
-
- String[] labels = null;
-
- switch (buttonType) {
- case OK :
- labels = new String[]{Messages.gettext("OK")};
- break;
- case OK_CANCEL :
- labels = new String[]{Messages.gettext("OK"), Messages.gettext("Cancel")};
- break;
- case YES_NO :
- labels = new String[]{Messages.gettext("Yes"), Messages.gettext("No")};
- break;
- case YES_NO_CANCEL :
- labels = new String[]{Messages.gettext("Yes"), Messages.gettext("No"), Messages.gettext("Cancel")};
- break;
- case CANCEL_OR_SAVE_AND_EXECUTE :
- labels = new String[]{Messages.gettext("Cancel"), Messages.gettext("Save and execute")};
- break;
- }
-
- messageBox.setButtonsLabels(labels);
-
- String iconName = null;
- switch(iconType) {
- case ERROR_ICON :
- iconName = "error";
- break;
- case INFORMATION_ICON :
- iconName = "info";
- break;
- case PASSWORD_ICON :
- iconName = "passwd";
- break;
- case QUESTION_ICON :
- iconName = "question";
- break;
- case WARNING_ICON :
- iconName = "warning";
- break;
- default :
- iconName = "scilab";
- break;
- }
-
- messageBox.setIcon(iconName);
-
- messageBox.setParentForLocation(parent);
-
- messageBox.displayAndWait();
- int choice = (messageBox.getSelectedButton() - 1); //zero indexed
-
- AnswerOption answer = AnswerOption.OK_OPTION;
-
- switch (buttonType) {
- case OK : //OK
- answer = AnswerOption.OK_OPTION;
- break;
- case OK_CANCEL :
- if (choice == 0) { //OK
- answer = AnswerOption.OK_OPTION;
- } else { //Cancel
- answer = AnswerOption.CANCEL_OPTION;
- }
- break;
- case YES_NO :
- if (choice == 0) { //Yes
- answer = AnswerOption.YES_OPTION;
- } else { //No
- answer = AnswerOption.NO_OPTION;
- }
- break;
- case YES_NO_CANCEL :
- if (choice == 0) { //Yes
- answer = AnswerOption.YES_OPTION;
- } else if (choice == 1) { //No
- answer = AnswerOption.NO_OPTION;
- } else { //Cancel
- answer = AnswerOption.CANCEL_OPTION;
- }
- break;
- case CANCEL_OR_SAVE_AND_EXECUTE :
- if (choice == 0) { //Yes
- answer = AnswerOption.CANCEL_OPTION;
- } else if (choice == 1) { //No
- answer = AnswerOption.SAVE_EXECUTE_OPTION;
- }
- break;
- }
- return answer;
- }
+ /**
+ * Message box button type
+ */
+ public enum ButtonType {
+ OK,
+ OK_CANCEL,
+ YES_NO,
+ YES_NO_CANCEL,
+ CANCEL_OR_SAVE_AND_EXECUTE
+ }
+
+ /**
+ * Message box button type
+ */
+
+ public enum IconType {
+ ERROR_ICON,
+ INFORMATION_ICON,
+ PASSWORD_ICON,
+ QUESTION_ICON,
+ WARNING_ICON,
+ SCILAB_ICON
+ }
+
+ public enum AnswerOption {
+ OK_OPTION,
+ CANCEL_OPTION,
+ YES_OPTION,
+ NO_OPTION,
+ SAVE_EXECUTE_OPTION
+ }
+ /**
+ * private constructor, only static functions
+ */
+ private ScilabModalDialog() {
+ }
+
+
+ /**
+ * @param messages : messages to display
+ * @param parent : tab to be used to set the location of the messagebox
+ * @param title : title of the message box
+ * default icon "scilab"
+ * default button "OK"
+ * @return index of the selected button
+ */
+ public static AnswerOption show(Tab parent, String[] messages) {
+ return show(parent, messages, Messages.gettext("Scilab Message"), IconType.SCILAB_ICON, ButtonType.OK);
+ }
+
+ /**
+ * @param message : message to display
+ * @param parent : tab to be used to set the location of the messagebox
+ * @param title : title of the message box
+ * default icon "scilab"
+ * default button "OK"
+ * @return index of the selected button
+ */
+ public static AnswerOption show(Tab parent, String message) {
+ return show(parent, new String[]{message}, Messages.gettext("Scilab Message"), IconType.SCILAB_ICON, ButtonType.OK);
+ }
+
+ /**
+ * @param messages : messages to display
+ * @param parent : tab to be used to set the location of the messagebox
+ * @param title : title of the message box
+ * default icon "Warning"
+ * default button "OK"
+ * @return index of the selected button
+ */
+ public static AnswerOption show(Tab parent, String[] messages, String title) {
+ return show(parent, messages, title, IconType.SCILAB_ICON, ButtonType.OK);
+ }
+
+ /**
+ * @param message : message to display
+ * @param parent : tab to be used to set the location of the messagebox
+ * @param title : title of the message box
+ * default icon "Warning"
+ * default button "OK"
+ * @return index of the selected button
+ */
+ public static AnswerOption show(Tab parent, String message, String title) {
+ return show(parent, new String[]{message}, title, IconType.SCILAB_ICON, ButtonType.OK);
+ }
+
+ /**
+ * @param messages : messages to display
+ * @param parent : tab to be used to set the location of the messagebox
+ * @param title : title of the message box
+ * @param iconType : message box icon ( see IconType )
+ * @return index of the selected button
+ */
+ public static AnswerOption show(Tab parent, String[] messages, String title, ScilabModalDialog.IconType iconType) {
+ return show(parent, messages, title, iconType, ButtonType.OK);
+ }
+
+ /**
+ * @param message : message to display
+ * @param parent : tab to be used to set the location of the messagebox
+ * @param title : title of the message box
+ * @param iconType : message box icon ( see IconType )
+ * @return index of the selected button
+ */
+ public static AnswerOption show(Tab parent, String message, String title, ScilabModalDialog.IconType iconType) {
+ return show(parent, new String[]{message}, title, iconType, ButtonType.OK);
+ }
+
+ /**
+ * @param message : message to display
+ * @param parent : tab to be used to set the location of the messagebox
+ * @param title : title of the message box
+ * @param iconType : message box icon ( see IconType )
+ * @param buttonType : message box type ( see ButtonType )
+ * @return index of the selected button
+ */
+ public static AnswerOption show(Tab parent, String message, String title,
+ ScilabModalDialog.IconType iconType, ScilabModalDialog.ButtonType buttonType) {
+ return show(parent, new String[]{message}, title, iconType, buttonType);
+ }
+
+ /**
+ * @param messages : messages to display
+ * @param parent : tab to be used to set the location of the messagebox
+ * @param title : title of the message box
+ * @param iconType : message box icon ( see IconType )
+ * @param buttonType : message box type ( see ButtonType )
+ * @return index of the selected button
+ */
+ public static AnswerOption show(Tab parent, String[] messages, String title,
+ ScilabModalDialog.IconType iconType, ScilabModalDialog.ButtonType buttonType) {
+ return show((Component) parent.getAsSimpleTab(), messages, title, iconType, buttonType);
+ }
+
+ /**
+ * @param messages : messages to display
+ * @param parent : component to be used to set the location of the messagebox
+ * @param title : title of the message box
+ * @param iconType : message box icon ( see IconType )
+ * @param buttonType : message box type ( see ButtonType )
+ * @return index of the selected button
+ */
+ public static AnswerOption show(Component parent, String[] messages, String title,
+ ScilabModalDialog.IconType iconType, ScilabModalDialog.ButtonType buttonType) {
+
+
+ MessageBox messageBox = ScilabMessageBox.createMessageBox();
+ messageBox.setTitle(title);
+ messageBox.setMessage(messages);
+
+ String[] labels = null;
+
+ switch (buttonType) {
+ case OK :
+ labels = new String[]{Messages.gettext("OK")};
+ break;
+ case OK_CANCEL :
+ labels = new String[]{Messages.gettext("OK"), Messages.gettext("Cancel")};
+ break;
+ case YES_NO :
+ labels = new String[]{Messages.gettext("Yes"), Messages.gettext("No")};
+ break;
+ case YES_NO_CANCEL :
+ labels = new String[]{Messages.gettext("Yes"), Messages.gettext("No"), Messages.gettext("Cancel")};
+ break;
+ case CANCEL_OR_SAVE_AND_EXECUTE :
+ labels = new String[]{Messages.gettext("Cancel"), Messages.gettext("Save and execute")};
+ break;
+ }
+
+ messageBox.setButtonsLabels(labels);
+
+ String iconName = null;
+ switch(iconType) {
+ case ERROR_ICON :
+ iconName = "error";
+ break;
+ case INFORMATION_ICON :
+ iconName = "info";
+ break;
+ case PASSWORD_ICON :
+ iconName = "passwd";
+ break;
+ case QUESTION_ICON :
+ iconName = "question";
+ break;
+ case WARNING_ICON :
+ iconName = "warning";
+ break;
+ default :
+ iconName = "scilab";
+ break;
+ }
+
+ messageBox.setIcon(iconName);
+
+ ((SwingScilabMessageBox) messageBox.getAsSimpleMessageBox()).setParentForLocation(parent);
+
+ messageBox.displayAndWait();
+ int choice = (messageBox.getSelectedButton() - 1); //zero indexed
+
+ AnswerOption answer = AnswerOption.OK_OPTION;
+
+ switch (buttonType) {
+ case OK : //OK
+ answer = AnswerOption.OK_OPTION;
+ break;
+ case OK_CANCEL :
+ if (choice == 0) { //OK
+ answer = AnswerOption.OK_OPTION;
+ } else { //Cancel
+ answer = AnswerOption.CANCEL_OPTION;
+ }
+ break;
+ case YES_NO :
+ if (choice == 0) { //Yes
+ answer = AnswerOption.YES_OPTION;
+ } else { //No
+ answer = AnswerOption.NO_OPTION;
+ }
+ break;
+ case YES_NO_CANCEL :
+ if (choice == 0) { //Yes
+ answer = AnswerOption.YES_OPTION;
+ } else if (choice == 1) { //No
+ answer = AnswerOption.NO_OPTION;
+ } else { //Cancel
+ answer = AnswerOption.CANCEL_OPTION;
+ }
+ break;
+ case CANCEL_OR_SAVE_AND_EXECUTE :
+ if (choice == 0) { //Yes
+ answer = AnswerOption.CANCEL_OPTION;
+ } else if (choice == 1) { //No
+ answer = AnswerOption.SAVE_EXECUTE_OPTION;
+ }
+ break;
+ }
+ return answer;
+ }
}
ScilabBridge.setViewingRegion(this, posX, posY, width, height);
}
-
/**
* @return size of the axes in pixels
*/
return ScilabBridge.getAxesSize(this);
}
-
/**
* @param newSize set a new axes size
*/
public void stopRotationRecording() {
ScilabBridge.stopRotationRecording(this);
}
-
}
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2007 - INRIA - 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
+ * are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
*
*/
package org.scilab.modules.gui.tab;
-
import org.scilab.modules.gui.checkbox.CheckBox;
import org.scilab.modules.gui.console.Console;
import org.scilab.modules.gui.canvas.Canvas;
*/
public interface SimpleTab {
- /**
- * Gets the Name of a tab
- * @return the Name of the tab
- */
- String getName();
-
- /**
- * Sets the Name of a tab
- * @param newTabName the Name we want to set to the tab
- */
- void setName(String newTabName);
-
- /**
- * We want to be able to add directly a Frame in a Tab.
- * @param member the member to add
- * @return the position of the frame in the member list.
- */
- int addMember(Frame member);
-
- /**
- * Remove a Frame from a Tab.
- * @param member the Frame to remove
- */
- void removeMember(Frame member);
-
- /**
- * We want to be able to add directly a Console in a Tab.
- * @param member the member to add
- * @return the position of the console in the member list.
- */
- int addMember(Console member);
-
- /**
- * We want to be able to add directly a HelpBrowser in a Tab.
- * @param member the member to add
- * @return the position of the HelpBrowser in the member list.
- */
- int addMember(HelpBrowser member);
-
- /**
- * We want to be able to add directly a Console in a Tab.
- * @param member the member to add
- * @return the position of the console in the member list.
- */
- int addMember(Canvas member);
-
- /**
- * We want to be able to add directly a pushbutton in a Tab.
- * @param member the pushbutton to add
- * @return the position of the pushbutton in the member list.
- */
- int addMember(PushButton member);
-
- /**
- * Remove a PushButton from a Tab.
- * @param member the pushbutton to add
- */
- void removeMember(PushButton member);
-
- /**
- * We want to be able to add directly a editbox in a Tab.
- * @param member the editbox to add
- * @return the position of the editbox in the member list.
- */
- int addMember(EditBox member);
-
- /**
- * Remove an EditBox from a Tab.
- * @param member the EditBox to remove
- */
- void removeMember(EditBox member);
-
- /**
- * We want to be able to add directly a label in a Tab.
- * @param member the label to add
- * @return the position of the label in the member list.
- */
- int addMember(Label member);
-
- /**
- * Remove a Label from a Tab.
- * @param member the Label to remove
- */
- void removeMember(Label member);
-
- /**
- * We want to be able to add directly a checkbox in a Tab.
- * @param member the checkbox to add
- * @return the position of the checkbox in the member list.
- */
- int addMember(CheckBox member);
-
- /**
- * Remove a CheckBox from a Tab.
- * @param member the CheckBox to remove
- */
- void removeMember(CheckBox member);
-
- /**
- * We want to be able to add directly a RadioButton in a Tab.
- * @param member the RadioButton to add
- * @return the position of the RadioButton in the member list.
- */
- int addMember(RadioButton member);
-
- /**
- * Remove a RadioButton from a Tab.
- * @param member the RadioButton to remove
- */
- void removeMember(RadioButton member);
-
- /**
- * We want to be able to add directly a Slider in a Tab.
- * @param member the Slider to add
- * @return the position of the Slider in the member list.
- */
- int addMember(Slider member);
-
- /**
- * Remove a Slider from a Tab.
- * @param member the Slider to remove
- */
- void removeMember(Slider member);
-
- /**
- * We want to be able to add directly a ListBox in a Tab.
- * @param member the ListBox to add
- * @return the position of the ListBox in the member list.
- */
- int addMember(ListBox member);
-
- /**
- * Remove a ListBox from a Tab.
- * @param member the ListBox to remove
- */
- void removeMember(ListBox member);
-
- /**
- * We want to be able to add directly a PopupMenu in a Tab.
- * @param member the PopupMenu to add
- * @return the position of the PopupMenu in the member list.
- */
- int addMember(PopupMenu member);
-
- /**
- * Remove a PopupMenu from a Tab.
- * @param member the PopupMenu to remove
- */
- void removeMember(PopupMenu member);
-
- /**
- * We want to be able to remove directly a Canvas from a Tab.
- * @param member canvas to remove
- */
- void removeMember(Canvas member);
-
-
- /**
- * We want to be able to add directly a PopupMenu in a Tab.
- * @param member the PopupMenu to add
- * @return the position of the PopupMenu in the member list.
- */
- int addMember(Tree member);
-
-
- /**
- * We want to be able to remove directly a Tree Overview from a Tab.
- * @param member Tree OverView to remove
- */
- void removeMember(Tree member);
-
- /**
- * Gets the size of an Tab (width and height)
- * @return the size of the Tab
- */
- Size getDims();
-
- /**
- * Sets the size of an Tab (width and height)
- * @param newSize the size we want to set to the Tab
- */
- void setDims(Size newSize);
-
- /**
- * Gets the position of an Tab (X-coordinate and Y-corrdinate)
- * @return the position of the Tab
- */
- Position getPosition();
-
- /**
- * Sets the position of an Tab (X-coordinate and Y-corrdinate)
- * @param newPosition the position we want to set to the Tab
- */
- void setPosition(Position newPosition);
-
- /**
- * Gets the visibility status of an Tab
- * @return the visibility status of the Tab (true if the Tab is visible, false if not)
- */
- boolean isVisible();
-
- /**
- * Sets the visibility status of an Tab
- * @param newVisibleState the visibility status we want to set for the Tab
- * (true if the Tab is visible, false if not)
- */
- void setVisible(boolean newVisibleState);
-
- /**
- * Draws an Tab
- */
- void draw();
-
- /**
- * Get the current status of the Tab in its parent
- * @return true is the tab is the tab currently "on top" in its parent
- */
- boolean isCurrentTab();
-
- /**
- * Set the parent window id for this tab
- * @param id the id of the parent window
- */
- void setParentWindowId(int id);
-
- /**
- * Get the parent window id for this tab
- * @return the id of the parent window
- */
- int getParentWindowId();
-
- /**
- * Get the MenuBar associated to this tab
- * @return MenuBar the MenuBar associated.
- */
- MenuBar getMenuBar();
-
- /**
- * Set the MenuBar associated to this tab
- * @param newMenuBar : the MenuBar to associate.
- */
- void setMenuBar(MenuBar newMenuBar);
-
- /**
- * Get the ToolBar associated to this tab
- * @return ToolBar the ToolBar associated.
- */
- ToolBar getToolBar();
-
- /**
- * Set the ToolBar associated to this tab
- * @param newToolBar : the ToolBar to associate.
- */
- void setToolBar(ToolBar newToolBar);
-
- /**
- * Get the InfoBar associated to this tab
- * @return infoBar the InfoBar associated.
- */
- TextBox getInfoBar();
-
- /**
- * Set the InfoBar associated to this tab
- * @param newInfoBar the InfoBar to associate.
- */
- void setInfoBar(TextBox newInfoBar);
-
- /**
- * Set the callback of the tab
- * @param callback the CallBack to set
- */
- void setCallback(CallBack callback);
-
- /**
- * Set this tab as the current tab of its parent Window
- */
- void setCurrent();
-
- /**
- * Set the background color of the tab.
- * @param red red channel of the color
- * @param green green channel
- * @param blue blue channel
- */
- void setBackground(double red, double green, double blue);
-
- /**
- * Specify whether the canvas should fit the parent tab size
- * (and consequently the scrollpane size) or not
- * @param onOrOff true to enable autoresize mode
- */
- void setAutoResizeMode(boolean onOrOff);
-
- /**
- * @return whether the resize mode is on or off
- */
- boolean getAutoResizeMode();
-
- /**
- * Get the part of the axes which is currently viewed
- * @return [x,y,w,h] array
- */
- int[] getViewingRegion();
-
- /**
- * Specify a new viewport for the axes
- * For SwingScilabCanvas viewport can not be modified
- * since it match the parent tab size
- * @param posX X coordinate of upper left point of the viewport within the canvas
- * @param posY Y coordinate of upper left point of the viewport within the canvas
- * @param width width of the viewport
- * @param height height of the viewport
- */
- void setViewingRegion(int posX, int posY, int width, int height);
-
-
- /**
- * @return size of the axes in pixels
- */
- Size getAxesSize();
-
-
- /**
- * @param newSize set a new axes size
- */
- void setAxesSize(Size newSize);
-
- /**
- * Set the event handler of the Canvas
- * @param command the name of the Scilab function to call
- */
- void setEventHandler(String command);
-
- /**
- * Set the status of the event handler of the Canvas
- * @param status is true to set the event handler active
- */
- void setEventHandlerEnabled(boolean status);
-
- /**
- * Get the displacement in pixel that should be used for rotating axes
- * @param displacement out parameter, [x,y] array of displacement in pixels
- * @return true if the displacement recording continue, false otherwise
- */
- boolean getRotationDisplacement(int[] displacement);
-
- /**
- * Asynchronous stop of rotation tracking.
- */
- void stopRotationRecording();
-
+ /**
+ * Gets the Name of a tab
+ * @return the Name of the tab
+ */
+ String getName();
+
+ /**
+ * Sets the Name of a tab
+ * @param newTabName the Name we want to set to the tab
+ */
+ void setName(String newTabName);
+
+ /**
+ * We want to be able to add directly a Frame in a Tab.
+ * @param member the member to add
+ * @return the position of the frame in the member list.
+ */
+ int addMember(Frame member);
+
+ /**
+ * Remove a Frame from a Tab.
+ * @param member the Frame to remove
+ */
+ void removeMember(Frame member);
+
+ /**
+ * We want to be able to add directly a Console in a Tab.
+ * @param member the member to add
+ * @return the position of the console in the member list.
+ */
+ int addMember(Console member);
+
+ /**
+ * We want to be able to add directly a HelpBrowser in a Tab.
+ * @param member the member to add
+ * @return the position of the HelpBrowser in the member list.
+ */
+ int addMember(HelpBrowser member);
+
+ /**
+ * We want to be able to add directly a Console in a Tab.
+ * @param member the member to add
+ * @return the position of the console in the member list.
+ */
+ int addMember(Canvas member);
+
+ /**
+ * We want to be able to add directly a pushbutton in a Tab.
+ * @param member the pushbutton to add
+ * @return the position of the pushbutton in the member list.
+ */
+ int addMember(PushButton member);
+
+ /**
+ * Remove a PushButton from a Tab.
+ * @param member the pushbutton to add
+ */
+ void removeMember(PushButton member);
+
+ /**
+ * We want to be able to add directly a editbox in a Tab.
+ * @param member the editbox to add
+ * @return the position of the editbox in the member list.
+ */
+ int addMember(EditBox member);
+
+ /**
+ * Remove an EditBox from a Tab.
+ * @param member the EditBox to remove
+ */
+ void removeMember(EditBox member);
+
+ /**
+ * We want to be able to add directly a label in a Tab.
+ * @param member the label to add
+ * @return the position of the label in the member list.
+ */
+ int addMember(Label member);
+
+ /**
+ * Remove a Label from a Tab.
+ * @param member the Label to remove
+ */
+ void removeMember(Label member);
+
+ /**
+ * We want to be able to add directly a checkbox in a Tab.
+ * @param member the checkbox to add
+ * @return the position of the checkbox in the member list.
+ */
+ int addMember(CheckBox member);
+
+ /**
+ * Remove a CheckBox from a Tab.
+ * @param member the CheckBox to remove
+ */
+ void removeMember(CheckBox member);
+
+ /**
+ * We want to be able to add directly a RadioButton in a Tab.
+ * @param member the RadioButton to add
+ * @return the position of the RadioButton in the member list.
+ */
+ int addMember(RadioButton member);
+
+ /**
+ * Remove a RadioButton from a Tab.
+ * @param member the RadioButton to remove
+ */
+ void removeMember(RadioButton member);
+
+ /**
+ * We want to be able to add directly a Slider in a Tab.
+ * @param member the Slider to add
+ * @return the position of the Slider in the member list.
+ */
+ int addMember(Slider member);
+
+ /**
+ * Remove a Slider from a Tab.
+ * @param member the Slider to remove
+ */
+ void removeMember(Slider member);
+
+ /**
+ * We want to be able to add directly a ListBox in a Tab.
+ * @param member the ListBox to add
+ * @return the position of the ListBox in the member list.
+ */
+ int addMember(ListBox member);
+
+ /**
+ * Remove a ListBox from a Tab.
+ * @param member the ListBox to remove
+ */
+ void removeMember(ListBox member);
+
+ /**
+ * We want to be able to add directly a PopupMenu in a Tab.
+ * @param member the PopupMenu to add
+ * @return the position of the PopupMenu in the member list.
+ */
+ int addMember(PopupMenu member);
+
+ /**
+ * Remove a PopupMenu from a Tab.
+ * @param member the PopupMenu to remove
+ */
+ void removeMember(PopupMenu member);
+
+ /**
+ * We want to be able to remove directly a Canvas from a Tab.
+ * @param member canvas to remove
+ */
+ void removeMember(Canvas member);
+
+
+ /**
+ * We want to be able to add directly a PopupMenu in a Tab.
+ * @param member the PopupMenu to add
+ * @return the position of the PopupMenu in the member list.
+ */
+ int addMember(Tree member);
+
+
+ /**
+ * We want to be able to remove directly a Tree Overview from a Tab.
+ * @param member Tree OverView to remove
+ */
+ void removeMember(Tree member);
+
+ /**
+ * Gets the size of an Tab (width and height)
+ * @return the size of the Tab
+ */
+ Size getDims();
+
+ /**
+ * Sets the size of an Tab (width and height)
+ * @param newSize the size we want to set to the Tab
+ */
+ void setDims(Size newSize);
+
+ /**
+ * Gets the position of an Tab (X-coordinate and Y-corrdinate)
+ * @return the position of the Tab
+ */
+ Position getPosition();
+
+ /**
+ * Sets the position of an Tab (X-coordinate and Y-corrdinate)
+ * @param newPosition the position we want to set to the Tab
+ */
+ void setPosition(Position newPosition);
+
+ /**
+ * Gets the visibility status of an Tab
+ * @return the visibility status of the Tab (true if the Tab is visible, false if not)
+ */
+ boolean isVisible();
+
+ /**
+ * Sets the visibility status of an Tab
+ * @param newVisibleState the visibility status we want to set for the Tab
+ * (true if the Tab is visible, false if not)
+ */
+ void setVisible(boolean newVisibleState);
+
+ /**
+ * Draws an Tab
+ */
+ void draw();
+
+ /**
+ * Get the current status of the Tab in its parent
+ * @return true is the tab is the tab currently "on top" in its parent
+ */
+ boolean isCurrentTab();
+
+ /**
+ * Set the parent window id for this tab
+ * @param id the id of the parent window
+ */
+ void setParentWindowId(int id);
+
+ /**
+ * Get the parent window id for this tab
+ * @return the id of the parent window
+ */
+ int getParentWindowId();
+
+ /**
+ * Get the MenuBar associated to this tab
+ * @return MenuBar the MenuBar associated.
+ */
+ MenuBar getMenuBar();
+
+ /**
+ * Set the MenuBar associated to this tab
+ * @param newMenuBar : the MenuBar to associate.
+ */
+ void setMenuBar(MenuBar newMenuBar);
+
+ /**
+ * Get the ToolBar associated to this tab
+ * @return ToolBar the ToolBar associated.
+ */
+ ToolBar getToolBar();
+
+ /**
+ * Set the ToolBar associated to this tab
+ * @param newToolBar : the ToolBar to associate.
+ */
+ void setToolBar(ToolBar newToolBar);
+
+ /**
+ * Get the InfoBar associated to this tab
+ * @return infoBar the InfoBar associated.
+ */
+ TextBox getInfoBar();
+
+ /**
+ * Set the InfoBar associated to this tab
+ * @param newInfoBar the InfoBar to associate.
+ */
+ void setInfoBar(TextBox newInfoBar);
+
+ /**
+ * Set the callback of the tab
+ * @param callback the CallBack to set
+ */
+ void setCallback(CallBack callback);
+
+ /**
+ * Set this tab as the current tab of its parent Window
+ */
+ void setCurrent();
+
+ /**
+ * Set the background color of the tab.
+ * @param red red channel of the color
+ * @param green green channel
+ * @param blue blue channel
+ */
+ void setBackground(double red, double green, double blue);
+
+ /**
+ * Specify whether the canvas should fit the parent tab size
+ * (and consequently the scrollpane size) or not
+ * @param onOrOff true to enable autoresize mode
+ */
+ void setAutoResizeMode(boolean onOrOff);
+
+ /**
+ * @return whether the resize mode is on or off
+ */
+ boolean getAutoResizeMode();
+
+ /**
+ * Get the part of the axes which is currently viewed
+ * @return [x,y,w,h] array
+ */
+ int[] getViewingRegion();
+
+ /**
+ * Specify a new viewport for the axes
+ * For SwingScilabCanvas viewport can not be modified
+ * since it match the parent tab size
+ * @param posX X coordinate of upper left point of the viewport within the canvas
+ * @param posY Y coordinate of upper left point of the viewport within the canvas
+ * @param width width of the viewport
+ * @param height height of the viewport
+ */
+ void setViewingRegion(int posX, int posY, int width, int height);
+
+ /**
+ * @return size of the axes in pixels
+ */
+ Size getAxesSize();
+
+ /**
+ * @param newSize set a new axes size
+ */
+ void setAxesSize(Size newSize);
+
+ /**
+ * Set the event handler of the Canvas
+ * @param command the name of the Scilab function to call
+ */
+ void setEventHandler(String command);
+
+ /**
+ * Set the status of the event handler of the Canvas
+ * @param status is true to set the event handler active
+ */
+ void setEventHandlerEnabled(boolean status);
+
+ /**
+ * Get the displacement in pixel that should be used for rotating axes
+ * @param displacement out parameter, [x,y] array of displacement in pixels
+ * @return true if the displacement recording continue, false otherwise
+ */
+ boolean getRotationDisplacement(int[] displacement);
+
+ /**
+ * Asynchronous stop of rotation tracking.
+ */
+ void stopRotationRecording();
}
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2007 - INRIA - Vincent Couvert
- *
+ *
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
- * are also available at
+ * are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
*
*/
*/
public interface Tab extends Container {
- /**
- * Gets a much more dummy Objects.
- * @return the component.
- */
- SimpleTab getAsSimpleTab();
-
- /**
- * Gets the Name of a tab
- * @return the Name of the tab
- */
- String getName();
-
- /**
- * Sets the Name of a tab
- * @param newTabName the Name we want to set to the tab
- */
- void setName(String newTabName);
-
- /**
- * We want to be able to add directly a Canvas in a Tab.
- * @param member the member to add
- * @return the position of the canvas in the member list.
- */
- int addMember(Canvas member);
-
- /**
- * We want to be able to add directly a Console in a Tab.
- * @param member the member to add
- * @return the position of the canvas in the member list.
- */
- int addMember(Console member);
-
- /**
- * We want to be able to add directly a HelpBrowser in a Tab.
- * @param member the member to add
- * @return the position of the HelpBrowser in the member list.
- */
- int addMember(HelpBrowser member);
-
- /**
- * We want to be able to add directly a Tree Overview in a Tab.
- * @param member the member to add
- * @return the position of the Tree Overview in the member list.
- */
- int addMember(Tree member);
-
- /**
- * We want to be able to add a Frame in a Tab.
- * @param member the member to add
- * @return the position of the Frame in the member list.
- */
- int addMember(Frame member);
-
- /**
- * Remove a Frame from a Tab.
- * @param member the Frame to remove
- */
- void removeMember(Frame member);
-
- /**
- * We want to be able to add directly a pushbutton in a Tab.
- * @param member the pushbutton to add
- * @return the position of the pushbutton in the member list.
- */
- int addMember(PushButton member);
-
- /**
- * Remove a PushButton from a Tab.
- * @param member the PushButton to remove
- */
- void removeMember(PushButton member);
-
- /**
- * We want to be able to add directly a editbox in a Tab.
- * @param member the editbox to add
- * @return the position of the editbox in the member list.
- */
- int addMember(EditBox member);
-
- /**
- * Remove an EditBox from a Tab.
- * @param member the EditBox to remove
- */
- void removeMember(EditBox member);
-
- /**
- * We want to be able to add directly a label in a Tab.
- * @param member the label to add
- * @return the position of the label in the member list.
- */
- int addMember(Label member);
-
- /**
- * Remove a Label from a Tab.
- * @param member the Label to remove
- */
- void removeMember(Label member);
-
- /**
- * We want to be able to add directly a checkbox in a Tab.
- * @param member the checkbox to add
- * @return the position of the checkbox in the member list.
- */
- int addMember(CheckBox member);
-
- /**
- * Remove a CheckBox from a Tab.
- * @param member the CheckBox to remove
- */
- void removeMember(CheckBox member);
-
- /**
- * We want to be able to add directly a RadioButton in a Tab.
- * @param member the RadioButton to add
- * @return the position of the RadioButton in the member list.
- */
- int addMember(RadioButton member);
-
- /**
- * Remove a RadioButton from a Tab.
- * @param member the RadioButton to remove
- */
- void removeMember(RadioButton member);
-
- /**
- * We want to be able to add directly a Slider in a Tab.
- * @param member the Slider to add
- * @return the position of the Slider in the member list.
- */
- int addMember(Slider member);
-
- /**
- * Remove a Slider from a Tab.
- * @param member the Slider to remove
- */
- void removeMember(Slider member);
-
- /**
- * We want to be able to add directly a ListBox in a Tab.
- * @param member the ListBox to add
- * @return the position of the ListBox in the member list.
- */
- int addMember(ListBox member);
-
- /**
- * Remove a ListBox from a Tab.
- * @param member the ListBox to remove
- */
- void removeMember(ListBox member);
-
- /**
- * We want to be able to add directly a PopupMenu in a Tab.
- * @param member the PopupMenu to add
- * @return the position of the PopupMenu in the member list.
- */
- int addMember(PopupMenu member);
-
- /**
- * Remove a PopupMenu from a Tab.
- * @param member the PopupMenu to remove
- */
- void removeMember(PopupMenu member);
-
- /**
- * We want to be able to remove directly a Canvas from a Tab.
- * @param member canvas to remove
- */
- void removeMember(Canvas member);
-
- /**
- * Destroy the tab.
- */
- void close();
-
- /**
- * Get the current status of the Tab in its parent
- * @return true is the tab is the tab currently "on top" in its parent
- */
- boolean isCurrentTab();
-
- /**
- * Set the parent window id for this tab
- * @param id the id of the parent window
- */
- void setParentWindowId(int id);
-
- /**
- * Get the parent window id for this tab
- * @return the id of the parent window
- */
- int getParentWindowId();
-
- /**
- * Set the callback of the tab
- * @param callback the CallBack to set
- */
- void setCallback(CallBack callback);
-
- /**
- * Get the parent Window
- * @return parent window of the tab object
- */
- Window getParentWindow();
-
- /**
- * Set this tab as the current tab of its parent Window
- */
- void setCurrent();
-
- /**
- * Set the background color of the tab.
- * @param red red channel of the color
- * @param green green channel
- * @param blue blue channel
- */
- void setBackground(double red, double green, double blue);
-
- /**
- * Specify whether the canvas should fit the parent tab size
- * (and consequently the scrollpane size) or not
- * @param onOrOff true to enable autoresize mode
- */
- void setAutoResizeMode(boolean onOrOff);
-
- /**
- * @return whether the resize mode is on or off
- */
- boolean getAutoResizeMode();
-
- /**
- * Get the part of the axes which is currently viewed
- * @return [x,y,w,h] array
- */
- int[] getViewingRegion();
-
- /**
- * Specify a new viewport for the axes
- * For SwingScilabCanvas viewport can not be modified
- * since it match the parent tab size
- * @param posX X coordinate of upper left point of the viewport within the canvas
- * @param posY Y coordinate of upper left point of the viewport within the canvas
- * @param width width of the viewport
- * @param height height of the viewport
- */
- void setViewingRegion(int posX, int posY, int width, int height);
-
-
- /**
- * @return size of the axes in pixels
- */
- Size getAxesSize();
-
-
- /**
- * @param newSize set a new axes size
- */
- void setAxesSize(Size newSize);
-
- /**
- * Set the event handler of the Canvas
- * @param command the name of the Scilab function to call
- */
- void setEventHandler(String command);
-
- /**
- * Set the status of the event handler of the Canvas
- * @param status is true to set the event handler active
- */
- void setEventHandlerEnabled(boolean status);
-
- /**
- * Get the displacement in pixel that should be used for rotating axes
- * @param displacement out parameter, [x,y] array of displacement in pixels
- * @return true if the displacement recording continue, false otherwise
- */
- boolean getRotationDisplacement(int[] displacement);
-
- /**
- * Asynchronous stop of rotation tracking.
- */
- void stopRotationRecording();
-
+ /**
+ * Gets a much more dummy Objects.
+ * @return the component.
+ */
+ SimpleTab getAsSimpleTab();
+
+ /**
+ * Gets the Name of a tab
+ * @return the Name of the tab
+ */
+ String getName();
+
+ /**
+ * Sets the Name of a tab
+ * @param newTabName the Name we want to set to the tab
+ */
+ void setName(String newTabName);
+
+ /**
+ * We want to be able to add directly a Canvas in a Tab.
+ * @param member the member to add
+ * @return the position of the canvas in the member list.
+ */
+ int addMember(Canvas member);
+
+ /**
+ * We want to be able to add directly a Console in a Tab.
+ * @param member the member to add
+ * @return the position of the canvas in the member list.
+ */
+ int addMember(Console member);
+
+ /**
+ * We want to be able to add directly a HelpBrowser in a Tab.
+ * @param member the member to add
+ * @return the position of the HelpBrowser in the member list.
+ */
+ int addMember(HelpBrowser member);
+
+ /**
+ * We want to be able to add directly a Tree Overview in a Tab.
+ * @param member the member to add
+ * @return the position of the Tree Overview in the member list.
+ */
+ int addMember(Tree member);
+
+ /**
+ * We want to be able to add a Frame in a Tab.
+ * @param member the member to add
+ * @return the position of the Frame in the member list.
+ */
+ int addMember(Frame member);
+
+ /**
+ * Remove a Frame from a Tab.
+ * @param member the Frame to remove
+ */
+ void removeMember(Frame member);
+
+ /**
+ * We want to be able to add directly a pushbutton in a Tab.
+ * @param member the pushbutton to add
+ * @return the position of the pushbutton in the member list.
+ */
+ int addMember(PushButton member);
+
+ /**
+ * Remove a PushButton from a Tab.
+ * @param member the PushButton to remove
+ */
+ void removeMember(PushButton member);
+
+ /**
+ * We want to be able to add directly a editbox in a Tab.
+ * @param member the editbox to add
+ * @return the position of the editbox in the member list.
+ */
+ int addMember(EditBox member);
+
+ /**
+ * Remove an EditBox from a Tab.
+ * @param member the EditBox to remove
+ */
+ void removeMember(EditBox member);
+
+ /**
+ * We want to be able to add directly a label in a Tab.
+ * @param member the label to add
+ * @return the position of the label in the member list.
+ */
+ int addMember(Label member);
+
+ /**
+ * Remove a Label from a Tab.
+ * @param member the Label to remove
+ */
+ void removeMember(Label member);
+
+ /**
+ * We want to be able to add directly a checkbox in a Tab.
+ * @param member the checkbox to add
+ * @return the position of the checkbox in the member list.
+ */
+ int addMember(CheckBox member);
+
+ /**
+ * Remove a CheckBox from a Tab.
+ * @param member the CheckBox to remove
+ */
+ void removeMember(CheckBox member);
+
+ /**
+ * We want to be able to add directly a RadioButton in a Tab.
+ * @param member the RadioButton to add
+ * @return the position of the RadioButton in the member list.
+ */
+ int addMember(RadioButton member);
+
+ /**
+ * Remove a RadioButton from a Tab.
+ * @param member the RadioButton to remove
+ */
+ void removeMember(RadioButton member);
+
+ /**
+ * We want to be able to add directly a Slider in a Tab.
+ * @param member the Slider to add
+ * @return the position of the Slider in the member list.
+ */
+ int addMember(Slider member);
+
+ /**
+ * Remove a Slider from a Tab.
+ * @param member the Slider to remove
+ */
+ void removeMember(Slider member);
+
+ /**
+ * We want to be able to add directly a ListBox in a Tab.
+ * @param member the ListBox to add
+ * @return the position of the ListBox in the member list.
+ */
+ int addMember(ListBox member);
+
+ /**
+ * Remove a ListBox from a Tab.
+ * @param member the ListBox to remove
+ */
+ void removeMember(ListBox member);
+
+ /**
+ * We want to be able to add directly a PopupMenu in a Tab.
+ * @param member the PopupMenu to add
+ * @return the position of the PopupMenu in the member list.
+ */
+ int addMember(PopupMenu member);
+
+ /**
+ * Remove a PopupMenu from a Tab.
+ * @param member the PopupMenu to remove
+ */
+ void removeMember(PopupMenu member);
+
+ /**
+ * We want to be able to remove directly a Canvas from a Tab.
+ * @param member canvas to remove
+ */
+ void removeMember(Canvas member);
+
+ /**
+ * Destroy the tab.
+ */
+ void close();
+
+ /**
+ * Get the current status of the Tab in its parent
+ * @return true is the tab is the tab currently "on top" in its parent
+ */
+ boolean isCurrentTab();
+
+ /**
+ * Set the parent window id for this tab
+ * @param id the id of the parent window
+ */
+ void setParentWindowId(int id);
+
+ /**
+ * Get the parent window id for this tab
+ * @return the id of the parent window
+ */
+ int getParentWindowId();
+
+ /**
+ * Set the callback of the tab
+ * @param callback the CallBack to set
+ */
+ void setCallback(CallBack callback);
+
+ /**
+ * Get the parent Window
+ * @return parent window of the tab object
+ */
+ Window getParentWindow();
+
+ /**
+ * Set this tab as the current tab of its parent Window
+ */
+ void setCurrent();
+
+ /**
+ * Set the background color of the tab.
+ * @param red red channel of the color
+ * @param green green channel
+ * @param blue blue channel
+ */
+ void setBackground(double red, double green, double blue);
+
+ /**
+ * Specify whether the canvas should fit the parent tab size
+ * (and consequently the scrollpane size) or not
+ * @param onOrOff true to enable autoresize mode
+ */
+ void setAutoResizeMode(boolean onOrOff);
+
+ /**
+ * @return whether the resize mode is on or off
+ */
+ boolean getAutoResizeMode();
+
+ /**
+ * Get the part of the axes which is currently viewed
+ * @return [x,y,w,h] array
+ */
+ int[] getViewingRegion();
+
+ /**
+ * Specify a new viewport for the axes
+ * For SwingScilabCanvas viewport can not be modified
+ * since it match the parent tab size
+ * @param posX X coordinate of upper left point of the viewport within the canvas
+ * @param posY Y coordinate of upper left point of the viewport within the canvas
+ * @param width width of the viewport
+ * @param height height of the viewport
+ */
+ void setViewingRegion(int posX, int posY, int width, int height);
+
+
+ /**
+ * @return size of the axes in pixels
+ */
+ Size getAxesSize();
+
+
+ /**
+ * @param newSize set a new axes size
+ */
+ void setAxesSize(Size newSize);
+
+ /**
+ * Set the event handler of the Canvas
+ * @param command the name of the Scilab function to call
+ */
+ void setEventHandler(String command);
+
+ /**
+ * Set the status of the event handler of the Canvas
+ * @param status is true to set the event handler active
+ */
+ void setEventHandlerEnabled(boolean status);
+
+ /**
+ * Get the displacement in pixel that should be used for rotating axes
+ * @param displacement out parameter, [x,y] array of displacement in pixels
+ * @return true if the displacement recording continue, false otherwise
+ */
+ boolean getRotationDisplacement(int[] displacement);
+
+ /**
+ * Asynchronous stop of rotation tracking.
+ */
+ void stopRotationRecording();
}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - 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.gui.tabfactory;
+
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+
+/**
+ * @author Calixte DENIZET
+ */
+public abstract class AbstractScilabTabFactory {
+
+ /**
+ * Abstract method which must implement a way to create a Tab with a given uuid
+ * @param uuid the uuid of the Tab to restore
+ * @return the corresponding Tab or null if this factory is unable to create the Tab (invalid uuid for example)
+ */
+ public abstract SwingScilabTab getTab(String uuid);
+
+ /**
+ * Abstract method which must implement a way to return true if the factory is able to build the Tab with given uuid
+ * @param uuid the uuid of the Tab to restore
+ * @return true if the factory is able to build the tab
+ */
+ public abstract boolean isAValidUUID(String uuid);
+
+ /**
+ * Abstract method which must implement a way to return the package containing the factory
+ * which is able to build the Tab with a given uuid
+ * @return the corresponding package or null if this factory is unable to create the Tab (invalid uuid for example)
+ */
+ public abstract String getPackage();
+
+ /**
+ * Abstract method which must implement a way to return the containing factory class
+ * which is able to build the Tab with a given uuid
+ * @return the corresponding package or null if this factory is unable to create the Tab (invalid uuid for example)
+ */
+ public abstract String getClassName();
+
+ /**
+ * Abstract method which must implement a way to return the application which produces the Tab
+ * @return the corresponding application or null if this factory is unable to create the Tab (invalid uuid for example)
+ */
+ public abstract String getApplication();
+}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - 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.gui.tabfactory;
+
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.helpbrowser.ScilabHelpBrowser;
+import org.scilab.modules.gui.utils.ClosingOperationsManager;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
+
+/**
+ * Class to create SciNotes instances
+ * @author Calixte DENIZET
+ */
+public class HelpBrowserTab {
+
+ /**
+ * @param uuid the uuid to restore
+ * @return a new SciNotes instance
+ */
+ public static SwingScilabTab getHelpBrowserInstance() {
+ final SwingScilabTab hb = ScilabHelpBrowser.createHelpBrowserTab();
+ ScilabTabFactory.getInstance().addToCache(hb);
+
+ ClosingOperationsManager.registerClosingOperation(hb, new ClosingOperationsManager.ClosingOperation() {
+
+ public boolean canClose() {
+ return true;
+ }
+
+ public void destroy() {
+ ScilabHelpBrowser.closeHelpBrowser();
+ }
+
+ public String askForClosing() {
+ return null;
+ }
+ });
+
+ ClosingOperationsManager.addDependencyWithRoot(hb);
+
+ return hb;
+ }
+}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - 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.gui.tabfactory;
+
+import org.scilab.modules.gui.helpbrowser.ScilabHelpBrowser;
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+
+/**
+ * The main Tab factory.
+ * A component which needs to restore a Tab with a given uuid must register its factory.
+ *
+ * @author Calixte DENIZET
+ */
+public class HelpBrowserTabFactory extends AbstractScilabTabFactory {
+
+ public static final String APPLICATION = "HelpBrowser";
+ public static final String PACKAGE = "";
+ public static final String CLASS = "org.scilab.modules.gui.tabfactory.HelpBrowserTabFactory";
+
+ private static HelpBrowserTabFactory instance;
+
+ /**
+ * Default constructor
+ */
+ public HelpBrowserTabFactory() {
+ if (instance == null) {
+ instance = this;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SwingScilabTab getTab(String uuid) {
+ return HelpBrowserTab.getHelpBrowserInstance();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPackage() {
+ return PACKAGE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getClassName() {
+ return CLASS;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getApplication() {
+ return APPLICATION;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isAValidUUID(String uuid) {
+ return ScilabHelpBrowser.HELPUUID.equals(uuid);
+ }
+
+ /**
+ * @return an instance of this factory
+ */
+ public static HelpBrowserTabFactory getInstance() {
+ new HelpBrowserTabFactory();
+
+ return instance;
+ }
+}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - 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.gui.tabfactory;
+
+import java.awt.Component;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.swing.JTextArea;
+
+import org.flexdock.docking.DockableFactory;
+
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.utils.WindowsConfigurationManager;
+import org.scilab.modules.jvm.LoadClassPath;
+import org.scilab.modules.localization.Messages;
+
+/**
+ * The main Tab factory.
+ * A component which needs to restore a Tab with a given uuid must register its factory.
+ *
+ * @author Calixte DENIZET
+ */
+public class ScilabTabFactory extends DockableFactory.Stub {
+
+ private static final ScilabTabFactory instance = new ScilabTabFactory();
+ private static final String EMPTYTAB = Messages.gettext("Empty tab");
+ private static final String NULLUUID = new UUID(0L, 0L).toString();
+ private static final String ERROR = Messages.gettext("The tab with uuid %s cannot be restored.\nPlease report a bug with the previous message and in attaching the file %s.");
+
+ /*
+ Certains components could depend an other Tab and this last one could be created before
+ to be requested by the Tab restorator. So we cache it to be sure to have the same instance.
+ */
+ private Map<String, SwingScilabTab> cache = new HashMap<String, SwingScilabTab>();
+ private Map<String, AbstractScilabTabFactory> factories = new HashMap<String, AbstractScilabTabFactory>();
+
+ /**
+ * Default constructor
+ */
+ protected ScilabTabFactory() { }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Component getDockableComponent(String uuid) {
+ return getTab(uuid);
+ }
+
+ /**
+ * Adds a new Tab factory
+ * @param factory the factory to add
+ */
+ public void addTabFactory(AbstractScilabTabFactory factory) {
+ if (!factories.containsKey(factory.getClassName())) {
+ factories.put(factory.getClassName(), factory);
+ }
+ }
+
+ /**
+ * Adds a new Tab factory
+ * @param pack the package to load in using LoadClassPath
+ * @param className the name of the factory
+ * @return the newly added factory
+ */
+ public AbstractScilabTabFactory addTabFactory(String pack, String className) {
+ AbstractScilabTabFactory factory = null;
+ if (!factories.containsKey(className)) {
+ if (pack != null && !pack.isEmpty()) {
+ LoadClassPath.loadOnUse(pack);
+ }
+ try {
+ Class clazz = Class.forName(className);
+ factory = (AbstractScilabTabFactory) clazz.newInstance();
+ addTabFactory(factory);
+ } catch (ClassNotFoundException e) {
+ System.out.println(e);
+ }
+ catch (IllegalAccessException e) {
+ System.out.println(e);
+ }
+ catch (InstantiationException e) {
+ System.out.println(e);
+ }
+ }
+
+ return factory;
+ }
+
+ /**
+ * Removes a Tab factory
+ * @param factory the factory to remove
+ */
+ public void removeTabFactory(AbstractScilabTabFactory factory) {
+ factories.remove(factory);
+ }
+
+ /**
+ * Creates a tab given an uuid
+ * @param uuid the uuid
+ * @return the corresponding tab
+ */
+ public SwingScilabTab getTab(String uuid) {
+ SwingScilabTab tab = cache.get(uuid);
+ if (tab != null) {
+ return tab;
+ }
+
+ for (String name : factories.keySet()) {
+ AbstractScilabTabFactory factory = factories.get(name);
+ if (factory.isAValidUUID(uuid)) {
+ tab = factory.getTab(uuid);
+ if (tab != null) {
+ cache.put(uuid, tab);
+ return tab;
+ }
+ }
+ }
+
+ return makeEmptyTab(uuid);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPackage(String uuid) {
+ for (String name : factories.keySet()) {
+ if (factories.get(name).isAValidUUID(uuid)) {
+ return factories.get(name).getPackage();
+ }
+ }
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getClassName(String uuid) {
+ for (String name : factories.keySet()) {
+ if (factories.get(name).isAValidUUID(uuid)) {
+ return factories.get(name).getClassName();
+ }
+ }
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getApplication(String uuid) {
+ for (String name : factories.keySet()) {
+ if (factories.get(name).isAValidUUID(uuid)) {
+ return factories.get(name).getApplication();
+ }
+ }
+ return "";
+ }
+
+ /**
+ * Clear the cache
+ */
+ public void clearCache() {
+ cache.clear();
+ }
+
+ public void removeFromCache(String uuid) {
+ cache.remove(uuid);
+ }
+
+ public SwingScilabTab getFromCache(String uuid) {
+ return cache.get(uuid);
+ }
+
+ public void addToCache(SwingScilabTab tab) {
+ cache.put(tab.getPersistentId(), tab);
+ }
+
+ /**
+ * @return the instace (this class should be used as a singleton)
+ */
+ public static ScilabTabFactory getInstance() {
+ return instance;
+ }
+
+ /**
+ * Make an empty tab
+ * @return an empty tab
+ */
+ private static final SwingScilabTab makeEmptyTab(String uuid) {
+ String u = uuid;
+ if (uuid == null || uuid.isEmpty()) {
+ u = NULLUUID;
+ }
+
+ SwingScilabTab tab = new SwingScilabTab(EMPTYTAB, u);
+ String text = String.format(ERROR, u, System.getProperty("user.home"));
+ JTextArea textarea = new JTextArea(text);
+ textarea.setEditable(false);
+ tab.setContentPane(textarea);
+
+ return tab;
+ }
+}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - 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.gui.utils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.swing.Action;
+
+import org.flexdock.docking.DockingConstants;
+
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog.AnswerOption;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog.ButtonType;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
+import org.scilab.modules.gui.tab.Tab;
+import org.scilab.modules.gui.tabfactory.ScilabTabFactory;
+import org.scilab.modules.gui.window.Window;
+import org.scilab.modules.localization.Messages;
+
+/**
+ * Class to handle the different closing operations.
+ * @author Calixte DENIZET
+ */
+public class ClosingOperationsManager {
+
+ private static final String EXIT_CONFIRM = Messages.gettext("Are you sure you want to close %s ?");
+ private static final String EXIT_CONFIRM_AND = Messages.gettext("Are you sure you want to close %s and %s ?");
+ private static final String EXIT = Messages.gettext("Exit");
+ private static final String NULLUUID = new UUID(0L, 0L).toString();
+ private static final Map<SwingScilabTab, ClosingOperation> closingOps = new HashMap<SwingScilabTab, ClosingOperation>();
+ private static final Map<SwingScilabTab, List<SwingScilabTab>> deps = new HashMap<SwingScilabTab, List<SwingScilabTab>>();
+
+ private static SwingScilabTab root;
+
+ static {
+ deps.put(null, new ArrayList<SwingScilabTab>());
+ }
+
+ /**
+ * Register a closing operation for a tab
+ * @param tab the associated tab
+ * @param op the closing operation
+ */
+ public static void registerClosingOperation(SwingScilabTab tab, ClosingOperation op) {
+ closingOps.put(tab, op);
+ }
+
+ /**
+ * Register a closing operation for a tab
+ * @param tab the associated tab
+ * @param op the closing operation
+ */
+ public static void registerClosingOperation(Tab tab, ClosingOperation op) {
+ registerClosingOperation((SwingScilabTab) tab.getAsSimpleTab(), op);
+ }
+
+ /**
+ * Start a closing operation on root
+ * @return true if the closing operation succeeded
+ */
+ public static boolean startClosingOperationOnRoot() {
+ SwingScilabWindow win = null;
+ if (root != null) {
+ // STD mode
+ return startClosingOperation(getWindow(root));
+ } else if (deps.get(null).size() != 0) {
+ // NW mode
+ List<SwingScilabTab> list = new ArrayList<SwingScilabTab>();
+ for (SwingScilabTab tab : deps.get(null)) {
+ collectTabsToClose(tab, list);
+ }
+ return close(list, null);
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Start a closing operation on a tab
+ * @param tab the tab to close
+ * @return true if the closing operation succeeded
+ */
+ public static boolean startClosingOperation(SwingScilabTab tab) {
+ return close(collectTabsToClose(tab), getWindow(tab));
+ }
+
+ /**
+ * Start a closing operation on a tab
+ * @param tab the tab to close
+ * @return true if the closing operation succeeded
+ */
+ public static boolean startClosingOperation(Tab tab) {
+ return startClosingOperation((SwingScilabTab) tab.getAsSimpleTab());
+ }
+
+ /**
+ * Start a closing operation on a window
+ * @return true if the closing operation succeeded
+ * @param window the window to close
+ */
+ public static boolean startClosingOperation(SwingScilabWindow window) {
+ List<SwingScilabTab> list = new ArrayList<SwingScilabTab>();
+ Object[] dockArray = window.getDockingPort().getDockables().toArray();
+ for (int i = 0; i < dockArray.length; i++) {
+ collectTabsToClose((SwingScilabTab) dockArray[i], list);
+ }
+ return close(list, window);
+ }
+
+ /**
+ * Start a closing operation on a window
+ * @param window the window to close
+ * @return true if the closing operation succeeded
+ */
+ public static boolean startClosingOperation(Window window) {
+ return startClosingOperation((SwingScilabWindow) window.getAsSimpleWindow());
+ }
+
+ /**
+ * Add a dependency between two tabs
+ * @param parent the parent tab
+ * @param child the child tab
+ */
+ public static void addDependency(SwingScilabTab parent, SwingScilabTab child) {
+ List<SwingScilabTab> children = deps.get(parent);
+ if (children == null) {
+ children = new ArrayList<SwingScilabTab>();
+ deps.put(parent, children);
+ }
+ children.add(child);
+ }
+
+ /**
+ * Add a dependency between two tabs
+ * @param parent the parent tab
+ * @param child the child tab
+ */
+ public static void addDependency(Tab parent, Tab child) {
+ addDependency((SwingScilabTab) parent.getAsSimpleTab(), (SwingScilabTab) child.getAsSimpleTab());
+ }
+
+ /**
+ * Add a dependency between two tabs
+ * @param parent the parent tab
+ * @param child the child tab
+ */
+ public static void addDependency(SwingScilabTab parent, Tab child) {
+ addDependency(parent, (SwingScilabTab) child.getAsSimpleTab());
+ }
+
+ /**
+ * Add a dependency between two tabs
+ * @param parent the parent tab
+ * @param child the child tab
+ */
+ public static void addDependency(Tab parent, SwingScilabTab child) {
+ addDependency((SwingScilabTab) parent.getAsSimpleTab(), child);
+ }
+
+ /**
+ * Add a dependency with the root tab
+ * @param child the child tab
+ */
+ public static void addDependencyWithRoot(SwingScilabTab child) {
+ addDependency(root, child);
+ }
+
+ /**
+ * Add a dependency with the root tab
+ * @param child the child tab
+ */
+ public static void addDependencyWithRoot(Tab child) {
+ addDependency(root, (SwingScilabTab) child.getAsSimpleTab());
+ }
+
+ /**
+ * Set the root element (normally the console)
+ * @param root the root element
+ */
+ public static void setRoot(SwingScilabTab tab) {
+ List<SwingScilabTab> list = deps.get(root);
+ deps.remove(root);
+ deps.put(tab, list);
+ root = tab;
+ }
+
+ /**
+ * Set the root element (normally the console)
+ * @param root the root element
+ */
+ public static void setRoot(Tab tab) {
+ setRoot((SwingScilabTab) tab.getAsSimpleTab());
+ }
+
+ /**
+ * Return the parent tab
+ * @param tab the child
+ * @return the parent tab
+ */
+ private static SwingScilabTab getParent(SwingScilabTab tab) {
+ for (SwingScilabTab key : deps.keySet()) {
+ List<SwingScilabTab> list = deps.get(key);
+ if (list != null && list.contains(tab)) {
+ return key;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the parent tab
+ * @param tab the child
+ * @return the parent tab
+ */
+ public static SwingScilabTab getElderTab(List<SwingScilabTab> tabs) {
+ if (tabs == null || tabs.size() == 0) {
+ return null;
+ }
+
+ int min = Integer.MAX_VALUE;
+ SwingScilabTab elder = null;
+ for (SwingScilabTab tab : tabs) {
+ int level = 0;
+ SwingScilabTab t = getParent(tab);
+ while (t != null) {
+ level++;
+ t = getParent(t);
+ }
+ if (level < min) {
+ elder = tab;
+ min = level;
+ }
+ }
+
+ return elder;
+ }
+
+ /**
+ * Close a list of tabs
+ * @param list the list
+ * @param window the window to use to center the modal dialog
+ * @return true if the closing operation succeeded
+ */
+ private static final boolean close(List<SwingScilabTab> list, SwingScilabWindow window) {
+ if (canClose(list, window)) {
+ // We remove the tabs which have a callback and no ClosingOperation
+ // To avoid annoying situations the tab will be undocked and closed
+ List<SwingScilabTab> tabsToRemove = new ArrayList<SwingScilabTab>();
+ for (SwingScilabTab tab : list) {
+ if (closingOps.get(tab) == null) {
+ tab.setVisible(false);
+ tab.getActionButton("undock").getAction().actionPerformed(null);
+ Action action = ((SciClosingAction) tab.getActionButton(DockingConstants.CLOSE_ACTION).getAction()).getAction();
+ if (action == null) {
+ getWindow(tab).removeTabs(new SwingScilabTab[]{tab});
+ } else {
+ action.actionPerformed(null);
+ }
+ tabsToRemove.add(tab);
+ }
+ }
+ list.removeAll(tabsToRemove);
+
+ // we group the tabs by win
+ Map<SwingScilabWindow, List<SwingScilabTab>> map = new HashMap<SwingScilabWindow, List<SwingScilabTab>>();
+ for (SwingScilabTab tab : list) {
+ SwingScilabWindow win = getWindow(tab);
+ if (!map.containsKey(win)) {
+ map.put(win, new ArrayList<SwingScilabTab>());
+ }
+ map.get(win).add(tab);
+ }
+
+ List<SwingScilabWindow> winsWithOneTab = new ArrayList<SwingScilabWindow>();
+ List<SwingScilabWindow> windowsToClose = new ArrayList<SwingScilabWindow>();
+ for (SwingScilabWindow win : map.keySet()) {
+ List<SwingScilabTab> listTabs = map.get(win);
+ int nbDockedTabs = win.getNbDockedObjects();
+ if (nbDockedTabs == listTabs.size()) {
+ // all the tabs in the window are removed so we save the win state
+ WindowsConfigurationManager.saveWindowProperties(win);
+ windowsToClose.add(win);
+ } else {
+ if (nbDockedTabs - listTabs.size() == 1) {
+ winsWithOneTab.add(win);
+ }
+ // the window will stay opened
+ for (SwingScilabTab tab : listTabs) {
+ WindowsConfigurationManager.saveTabProperties(tab, true);
+ }
+ }
+ }
+
+ // If a parent and a child are removed, we make a dependency between them
+ // The parent restoration will imply the child one
+ for (SwingScilabTab tab : list) {
+ SwingScilabTab parent = getParent(tab);
+ if (list.contains(parent) || parent == null) {
+ if (parent != null) {
+ WindowsConfigurationManager.makeDependency(parent.getPersistentId(), tab.getPersistentId());
+ } else if (!tab.getPersistentId().equals(NULLUUID)) {
+ // if the parent is null, we make a dependency with the console which is the default root
+ WindowsConfigurationManager.makeDependency(NULLUUID, tab.getPersistentId());
+ }
+ } else {
+ WindowsConfigurationManager.removeDependency(tab.getPersistentId());
+ }
+ }
+
+ WindowsConfigurationManager.clean();
+ SwingScilabTab console = null;
+ // We destroy all the tabs: children before parents.
+ for (SwingScilabTab tab : list) {
+ tab.setVisible(false);
+ if (!tab.getPersistentId().equals(NULLUUID)) {
+ try {
+ closingOps.get(tab).destroy();
+ } catch (Exception e) {
+ // An error can occured during the destroy operation
+ // We show it but it mustn't avoid the window destruction
+ e.printStackTrace();
+ }
+ } else {
+ console = tab;
+ }
+ }
+
+ // We remove the tabs in each window
+ // The tabs are removed in one time to avoid that the ActiveDockableTracker tryes to give the activation to a removed tab
+ for (SwingScilabWindow win : map.keySet()) {
+ win.removeTabs(map.get(win).toArray(new SwingScilabTab[0]));
+ }
+
+ // It stays one docked tab so we remove close and undock action
+ for (SwingScilabWindow win : winsWithOneTab) {
+ Object[] dockArray = win.getDockingPort().getDockables().toArray();
+ SwingScilabTab.removeActions((SwingScilabTab) dockArray[0]);
+ }
+
+ // We wait until all the windows are definitly closed
+ while (windowsToClose.size() != 0) {
+ List<SwingScilabWindow> toRemove = new ArrayList<SwingScilabWindow>();
+ for (SwingScilabWindow win : windowsToClose) {
+ WindowsConfigurationManager.removeWin(win.getUUID());
+ if (win.isDisplayable()) {
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) { }
+ } else {
+ toRemove.add(win);
+ }
+ }
+ windowsToClose.removeAll(toRemove);
+ }
+
+ // We remove the tabs from the cache
+ for (SwingScilabTab tab : list) {