15
15
import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.buildCall;
16
16
import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.synchronousScilabExec;
18
import java.awt.GraphicsEnvironment;
18
19
import java.awt.image.BufferedImage;
19
20
import java.io.File;
20
21
import java.io.IOException;
26
27
import javax.imageio.ImageIO;
27
28
import javax.swing.SwingUtilities;
29
import ncsa.hdf.hdf5lib.exceptions.HDF5Exception;
31
30
import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
32
31
import org.scilab.modules.graph.utils.ScilabExported;
33
import org.scilab.modules.hdf5.read.H5Read;
32
import org.scilab.modules.javasci.JavasciException;
33
import org.scilab.modules.javasci.Scilab;
34
34
import org.scilab.modules.localization.Messages;
35
35
import org.scilab.modules.types.ScilabTList;
36
36
import org.scilab.modules.xcos.Xcos;
132
132
* Load an xcos palette into the palette manager
135
* full path to the scilab exported palette
135
* the scilab exported palette variable name
136
136
* @param category
137
137
* TreePath of the palette
138
* @throws JavasciException
139
* on invocation error
139
141
@ScilabExported(module = XCOS, filename = PALETTE_GIWS_XML)
140
public static void loadPal(final String path, final String[] category) {
142
public static void loadPal(final String name, final String[] category) throws JavasciException {
144
* If the env. is headless only perform fake loading to assert data
147
if (GraphicsEnvironment.isHeadless()) {
148
LOG.warning("Headless environment detected, only perform sanity check");
149
loadPalHeadless(name);
142
154
* Import the palette
144
final ScilabTList data = new ScilabTList();
145
final String file = new File(path).getAbsolutePath();
147
final int fileId = H5Read.openFile(file);
148
H5Read.readDataFromFile(fileId, data);
149
H5Read.closeFile(fileId);
150
} catch (final HDF5Exception e) {
151
throw new RuntimeException(String.format(UNABLE_TO_IMPORT, file), e);
156
final ScilabTList data = (ScilabTList) Scilab.getInCurrentScilabSession(name);
155
159
* handle shared data on the EDT thread
158
162
SwingUtilities.invokeAndWait(new Runnable() {
160
164
public void run() {
162
* Decode the style part of the palette
164
final mxStylesheet styleSheet = Xcos.getInstance().getStyleSheet();
166
new StyleElement().decode(data, styleSheet);
167
} catch (final ScicosFormatException e) {
168
throw new RuntimeException(e);
171
// reload all the opened diagram (clear states)
172
for (final XcosDiagram d : Xcos.getInstance().openedDiagrams()) {
174
final mxGraphView view = d.getView();
179
final mxGraphComponent comp = d.getAsComponent();
186
final PaletteNode node = getPathNode(category, true);
187
if (!(node instanceof Category)) {
188
throw new RuntimeException(String.format(WRONG_INPUT_ARGUMENT_S_INVALID_TREE_PATH, "category"));
190
final Category cat = (Category) node;
193
* Adding the palette tree part of the palette
197
pal = new PreLoadedElement().decode(data, new PreLoaded.Dynamic());
198
} catch (final ScicosFormatException e) {
199
throw new RuntimeException(e);
201
cat.getNode().add(pal);
204
PaletteNode.refreshView(pal);
167
* Decode the style part of the palette
169
final mxStylesheet styleSheet = Xcos.getInstance().getStyleSheet();
171
new StyleElement().decode(data, styleSheet);
172
} catch (final ScicosFormatException e) {
173
throw new RuntimeException(e);
176
// reload all the opened diagram (clear states)
177
for (final XcosDiagram d : Xcos.getInstance().openedDiagrams()) {
179
final mxGraphView view = d.getView();
184
final mxGraphComponent comp = d.getAsComponent();
191
final PaletteNode node = getPathNode(category, true);
192
if (!(node instanceof Category)) {
193
throw new RuntimeException(String.format(WRONG_INPUT_ARGUMENT_S_INVALID_TREE_PATH, "category"));
195
final Category cat = (Category) node;
198
* Adding the palette tree part of the palette
202
pal = new PreLoadedElement().decode(data, new PreLoaded.Dynamic());
203
} catch (final ScicosFormatException e) {
204
throw new RuntimeException(e);
206
cat.getNode().add(pal);
209
PaletteNode.refreshView(pal);
210
} catch (Exception e) {
207
215
} catch (final InterruptedException e) {
229
private static final void loadPalHeadless(final String name) throws JavasciException {
231
final ScilabTList data = (ScilabTList) Scilab.getInCurrentScilabSession(name);
234
new StyleElement().decode(data, new mxStylesheet());
236
// palette data check
237
new PreLoadedElement().decode(data, new PreLoaded.Dynamic());
239
} catch (ScicosFormatException e) {
240
throw new RuntimeException(e);
222
245
* Load an xcos palette into the palette manager at the root category.
225
* full path to the scilab exported palette
248
* the scilab exported palette variable name
249
* @throws JavasciException
250
* on invocation error
227
252
@ScilabExported(module = XCOS, filename = PALETTE_GIWS_XML)
228
public static void loadPal(final String path) {
253
public static void loadPal(final String name) throws JavasciException {