<path value="@JGRAPHX@" load="onUse">
<load on="Xcos"/>
+ <load on="documentationGeneration"/>
</path>
<path value="@SCIRENDERER@" load="onUse">
<!-- Temp. loaded at startup -->
<path value="$SCILAB/modules/types/jar/org.scilab.modules.types.jar"/>
-
-<path value="$SCILAB/modules/xcos/jar/org.scilab.modules.xcos.jar" load="onUse">
- <load on="Xcos"/>
-</path>
<!-- END -->
<!-- Documentation (not mandatory) -->
<load on="SciNotes"/>
</path>
+<!-- Xcos module -->
+<path value="$SCILAB/modules/xcos/jar/org.scilab.modules.xcos.jar" load="onUse">
+ <load on="Xcos"/>
+ <load on="documentationGeneration"/>
+</path>
+
+<path value="$SCILAB/modules/graph/jar/org.scilab.modules.graph.jar" load="onUse">
+ <load on="Xcos"/>
+ <load on="documentationGeneration"/>
+</path>
<!-- TO DO Load only when we need -->
<path value="$SCILAB/modules/graphic_objects/jar/org.scilab.modules.graphic_objects.jar"/>
<path value="$SCILAB/modules/ui_data/jar/org.scilab.modules.ui_data.jar"/>
<path value="$SCILAB/modules/javasci/jar/org.scilab.modules.javasci.jar"/>
-<!-- TO DO Load only when we need -->
-<path value="$SCILAB/modules/graph/jar/org.scilab.modules.graph.jar"/>
-
<path value="$SCILAB/modules/history_browser/jar/org.scilab.modules.history_browser.jar" disableUnderMode="NW"/>
</classpaths>
<path value="$SCILAB/thirdparty/jgraphx.jar" load="onUse">
<load on="Xcos"/>
+ <load on="documentationGeneration"/>
+</path>
+
+<path value="$SCILAB/thirdparty/scirenderer-1.0.2.jar" load="onUse">
+ <load on="graphics"/>
+ <load on="graphic_ojects"/>
+ <load on="Xcos"/>
</path>
<path value="$SCILAB/thirdparty/jogl2.jar" load="onUse">
<load on="Xcos"/>
</path>
-<path value="$SCILAB/thirdparty/scirenderer-1.0.2.jar" load="onUse">
- <load on="graphics"/>
- <load on="graphic_ojects"/>
- <load on="Xcos"/>
-</path>
-
<!-- Temp. loaded at startup -->
<path value="$SCILAB/modules/types/jar/org.scilab.modules.types.jar"/>
-
-<path value="$SCILAB/modules/xcos/jar/org.scilab.modules.xcos.jar" load="onUse">
- <load on="Xcos"/>
-</path>
<!-- END -->
<!-- Documentation (not mandatory) -->
<load on="SciNotes"/>
</path>
+<!-- Xcos module -->
+<path value="$SCILAB/modules/xcos/jar/org.scilab.modules.xcos.jar" load="onUse">
+ <load on="Xcos"/>
+ <load on="documentationGeneration"/>
+</path>
+
+<path value="$SCILAB/modules/graph/jar/org.scilab.modules.graph.jar" load="onUse">
+ <load on="Xcos"/>
+ <load on="documentationGeneration"/>
+</path>
<!-- TO DO Load only when we need -->
<path value="$SCILAB/modules/graphic_objects/jar/org.scilab.modules.graphic_objects.jar"/>
<path value="$SCILAB/modules/ui_data/jar/org.scilab.modules.ui_data.jar"/>
<path value="$SCILAB/modules/javasci/jar/org.scilab.modules.javasci.jar"/>
- <!-- TO DO Load only when we need -->
-<path value="$SCILAB/modules/graph/jar/org.scilab.modules.graph.jar"/>
-
<path value="$SCILAB/modules/history_browser/jar/org.scilab.modules.history_browser.jar" disableUnderMode="NW"/>
</classpaths>
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
+import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import com.mxgraph.model.mxICell;
// Paint the foreground color after the real paint
addListener(mxEvent.AFTER_PAINT, new mxEventSource.mxIEventListener() {
+ @Override
public void invoke(Object sender, mxEventObject evt) {
Graphics g = (Graphics) evt.getProperty("g");
});
}
}
+
+ /*
+ * Disable some handlers in case of an headless env.
+ */
+
+ @Override
+ protected void createHandlers() {
+ if (GraphicsEnvironment.isHeadless()) {
+ return;
+ }
+
+ super.createHandlers();
+ }
}
import org.scilab.modules.helptools.image.MathMLImageConverter;
import org.scilab.modules.helptools.image.ScilabImageConverter;
import org.scilab.modules.helptools.image.SVGImageConverter;
+import org.scilab.modules.helptools.image.XcosImageConverter;
import org.scilab.modules.helptools.scilab.ScilabLexer;
import org.scilab.modules.helptools.scilab.HTMLScilabCodeHandler;
import org.scilab.modules.helptools.scilab.AbstractScilabCodeHandler;
ImageConverter.registerExternalImageConverter(MathMLImageConverter.getInstance(type));
ImageConverter.registerExternalImageConverter(SVGImageConverter.getInstance(type));
ImageConverter.registerExternalImageConverter(ScilabImageConverter.getInstance(type));
+ ImageConverter.registerExternalImageConverter(XcosImageConverter.getInstance(type));
}
/**
mimeMap.addMimeTypes("type=image/mathml exts=mml,mathml");
mimeMap.addMimeTypes("type=image/svg exts=svg");
mimeMap.addMimeTypes("type=image/scilab exts=sce");
+ mimeMap.addMimeTypes("type=image/scilab-xcos exts=xcos,zcos");
}
/**
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2012 - Scilab Enterprises - Clément David
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.helptools.image;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.util.Map;
+
+import javax.imageio.ImageIO;
+
+import org.scilab.modules.helptools.HTMLDocbookTagConverter;
+import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.io.XcosFileType;
+
+import com.mxgraph.swing.mxGraphComponent;
+import com.mxgraph.util.mxCellRenderer;
+
+/**
+ * Xcos schema to PNG converter
+ */
+public class XcosImageConverter implements ExternalImageConverter {
+
+ private static XcosImageConverter instance;
+ private final HTMLDocbookTagConverter.GenerationType type;
+
+ private XcosImageConverter(HTMLDocbookTagConverter.GenerationType type) {
+ this.type = type;
+ }
+
+ @Override
+ public String getMimeType() {
+ return "image/scilab-xcos";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean mustRegenerate() {
+ return false;
+ }
+
+ /**
+ * Since this a singleton class...
+ *
+ * @return this
+ */
+ public static XcosImageConverter getInstance(HTMLDocbookTagConverter.GenerationType type) {
+ if (instance == null) {
+ instance = new XcosImageConverter(type);
+ }
+
+ return instance;
+ }
+
+ public static XcosImageConverter getInstance() {
+ return instance;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Redirect to the scilab code implementation.
+ */
+ @Override
+ public String convertToImage(String currentFile, String code, Map<String, String> attributes, File imageFile, String imageName) {
+ return ScilabImageConverter.getInstance().convertToImage(currentFile, code, attributes, imageFile, imageName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String convertToImage(File schema, Map<String, String> attributes, File imageFile, String imageName) {
+ try {
+ final String name = schema.getName();
+ return convertToPNG(name, schema.getAbsolutePath(), imageFile, imageName);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.err.printf("Problem when exporting Xcos schema %s !\n%s\n", schema, e.toString());
+ }
+
+ return null;
+ }
+
+ private final String convertToPNG(final String helpID, final String xcosFile, final File imageFile, final String imageName) throws Exception {
+ final XcosDiagram diag = new XcosDiagram();
+ diag.installListeners();
+
+ final XcosFileType filetype = XcosFileType.findFileType(xcosFile);
+ filetype.load(xcosFile, diag);
+
+ final mxGraphComponent graphComponent = diag.getAsComponent();
+
+ final BufferedImage image = mxCellRenderer.createBufferedImage(diag, null, 1, null, graphComponent.isAntiAlias(), null, graphComponent.getCanvas());
+ ImageIO.write(image, "png", imageFile);
+
+ return getHTMLCodeToReturn(helpID, "<img src=\'" + imageName + "\'/>");
+ }
+
+ public String getHTMLCodeToReturn(String filename, String imageTag) {
+ if (type == HTMLDocbookTagConverter.GenerationType.WEB) {
+ /* Provide a tooltip */
+ return "<div rel='tooltip' title='" + filename + "'>" + imageTag + "</div>";
+ } else {
+ /*
+ * No tooltip in the javahelp browser ... too limited html
+ * capabilities
+ */
+ return imageTag;
+ }
+ }
+}
*
-->
<project default="all" name="build-all-jar">
- <!-- Call World
+ <!-- Call World
The main idea is to build at once all the var files
-->
- <property name="target-jar" value="jar"/>
- <property file="../../scilab-lib.properties"/>
-
- <!-- Order matter : fixed order to avoid dependency handling-->
- <target name="all" depends="localization, commons, history_manager, jvm, action_binding, graphic_objects, completion, console, renderer, graphic_export, gui, core, helptools, types, scinotes, ui_data, history_browser, javasci, graph, xcos, preferences" />
- <target name="clean">
- <antcall target="all">
- <param name="target-jar" value="clean"/>
- </antcall>
- </target>
- <target name="test"/>
-
- <target name="action_binding">
- <ant antfile="../action_binding/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="commons">
- <ant antfile="../commons/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="completion">
- <ant antfile="../completion/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="console">
- <ant antfile="../console/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="core">
- <ant antfile="../core/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="graph">
- <ant antfile="../graph/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="graphic_export">
- <ant antfile="../graphic_export/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="graphic_objects">
- <ant antfile="../graphic_objects/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="gui">
- <ant antfile="../gui/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="helptools">
- <ant antfile="../helptools/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="history_browser">
- <ant antfile="../history_browser/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="history_manager">
- <ant antfile="../history_manager/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="javasci" if="build_javasci">
- <ant antfile="../javasci/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="jvm">
- <ant antfile="../jvm/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="localization">
- <ant antfile="../localization/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="output_stream">
- <ant antfile="../output_stream/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="renderer">
- <ant antfile="../renderer/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="scinotes">
- <ant antfile="../scinotes/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="types">
- <ant antfile="../types/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="ui_data">
- <ant antfile="../ui_data/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="xcos" if="build_xcos" depends="javasci">
- <ant antfile="../xcos/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
- <target name="preferences">
- <ant antfile="../preferences/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
- </target>
+ <property name="target-jar" value="jar"/>
+ <property file="../../scilab-lib.properties"/>
+
+ <!-- Order matter : fixed order to avoid dependency handling-->
+ <target name="all" depends="localization, commons, history_manager, jvm, action_binding, graphic_objects, completion, console, renderer, graphic_export, gui, core, types, scinotes, ui_data, history_browser, javasci, graph, xcos, preferences, helptools" />
+ <target name="clean">
+ <antcall target="all">
+ <param name="target-jar" value="clean"/>
+ </antcall>
+ </target>
+ <target name="test"/>
+
+ <target name="action_binding">
+ <ant antfile="../action_binding/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="commons">
+ <ant antfile="../commons/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="completion">
+ <ant antfile="../completion/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="console">
+ <ant antfile="../console/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="core">
+ <ant antfile="../core/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="graph">
+ <ant antfile="../graph/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="graphic_export">
+ <ant antfile="../graphic_export/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="graphic_objects">
+ <ant antfile="../graphic_objects/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="gui">
+ <ant antfile="../gui/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="history_browser">
+ <ant antfile="../history_browser/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="history_manager">
+ <ant antfile="../history_manager/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="javasci" if="build_javasci">
+ <ant antfile="../javasci/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="jvm">
+ <ant antfile="../jvm/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="localization">
+ <ant antfile="../localization/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="output_stream">
+ <ant antfile="../output_stream/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="renderer">
+ <ant antfile="../renderer/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="scinotes">
+ <ant antfile="../scinotes/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="types">
+ <ant antfile="../types/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="ui_data">
+ <ant antfile="../ui_data/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="xcos" if="build_xcos" depends="javasci">
+ <ant antfile="../xcos/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="preferences">
+ <ant antfile="../preferences/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
+ <target name="helptools">
+ <ant antfile="../helptools/build.xml" target="${target-jar}" inheritRefs="false" inheritAll="false" />
+ </target>
</project>
<imagedata align="center" fileref="../../../examples/derivative_diag.png" valign="middle"/>
</imageobject>
</inlinemediaobject>
+<scilab:image><![CDATA[
+importXcosDiagram(SCI + "/modules/xcos/examples/continuous_pal/DERIV_Example.xcos");
+xcos_simulate(scs_m, 4);
+]]></scilab:image>
</para>
</refsection>
<refsection id="Interfacingfunction_DERIV">
package org.scilab.modules.xcos;
import java.awt.Component;
-import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
private static final List<String> MXGRAPH_VERSIONS = null;
private static final List<String> BATIK_VERSIONS = Arrays.asList("1.7", "1.8pre", "1.8");
- private static final String IS_HEADLESS = Messages.gettext("a graphical environment is needed.");
private static final String UNABLE_TO_LOAD_JGRAPHX = Messages.gettext("Unable to load the jgraphx library.\nExpecting version %s ; Getting version %s .");
private static final String UNABLE_TO_LOAD_BATIK = Messages.gettext("Unable to load the Batik library. \nExpecting version %s ; Getting version %s .");
private void checkDependencies() {
final ClassLoader loader = ClassLoader.getSystemClassLoader();
- /* Check not headless */
- if (GraphicsEnvironment.isHeadless()) {
- throw new RuntimeException(IS_HEADLESS);
- }
-
/* JGraphx */
String mxGraphVersion = "";
try {
package org.scilab.modules.xcos.graph.swing;
+import java.awt.GraphicsEnvironment;
import java.awt.MouseInfo;
import org.scilab.modules.graph.ScilabComponent;
*/
@Override
protected mxGraphHandler createGraphHandler() {
+ if (GraphicsEnvironment.isHeadless()) {
+ return null;
+ }
+
return new GraphHandler(this);
}