8900d1559f9c3c0fcc9be90b5d245045b646e290
[scilab.git] / scilab / modules / graphic_objects / src / java / org / scilab / modules / graphic_objects / builder / Builder.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
4  * Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
5  *
6  * This file must be used under the terms of the CeCILL.
7  * This source file is licensed as described in the file COPYING, which
8  * you should have received as part of this distribution.  The terms
9  * are also available at
10  * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
11  *
12  */
13
14 package org.scilab.modules.graphic_objects.builder;
15
16 import java.util.ArrayList;
17 import java.util.StringTokenizer;
18
19 import org.scilab.modules.graphic_objects.ScilabNativeView;
20 import org.scilab.modules.graphic_objects.arc.Arc;
21 import org.scilab.modules.graphic_objects.axes.Axes;
22 import org.scilab.modules.graphic_objects.axis.Axis;
23 import org.scilab.modules.graphic_objects.fec.Fec;
24 import org.scilab.modules.graphic_objects.figure.Figure;
25 import org.scilab.modules.graphic_objects.figure.Figure.BarType;
26 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
27 import org.scilab.modules.graphic_objects.graphicModel.GraphicModel;
28 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
29 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject.Type;
30 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
31 import org.scilab.modules.graphic_objects.imageplot.Imageplot;
32 import org.scilab.modules.graphic_objects.label.Label;
33 import org.scilab.modules.graphic_objects.legend.Legend;
34 import org.scilab.modules.graphic_objects.lighting.Light;
35 import org.scilab.modules.graphic_objects.lighting.Light.LightType;
36 import org.scilab.modules.graphic_objects.polyline.Polyline;
37 import org.scilab.modules.graphic_objects.rectangle.Rectangle;
38 import org.scilab.modules.graphic_objects.surface.Surface;
39 import org.scilab.modules.graphic_objects.textObject.Font;
40 import org.scilab.modules.graphic_objects.textObject.Text;
41 import org.scilab.modules.graphic_objects.vectfield.Champ;
42 import org.scilab.modules.graphic_objects.vectfield.Segs;
43
44 public final class Builder {
45     public final static int createRect(int parentSubwin, double x, double y,
46                                        double height, double width, int foreground,
47                                        int background, int isfilled, int isline) {
48         GraphicController controller = GraphicController.getController();
49         Axes axes = (Axes)controller.getObjectFromId(parentSubwin);
50
51         if (height < 0 || width < 0) {
52             return 0;
53         }
54
55         Integer iRect = controller.askObject(Type.RECTANGLE, false);
56
57         /*
58          * Sets the rectangle's parent in order to initialize the former's Contoured properties
59          * with the latter's values (cloneGraphicContext call below)
60          */
61
62         Rectangle rect = (Rectangle) controller.getObjectFromId(iRect);
63         rect.setUpperLeftPoint(new Double[] {x, y, 0.0});
64         rect.setHeight(height);
65         rect.setWidth(width);
66
67         rect.setVisible(axes.getVisible());
68
69         /* Clip state and region */
70         /* To be checked for consistency */
71
72         rect.setClipBox(axes.getClipBox());
73         rect.setClipBoxSet(axes.getClipBoxSet());
74         rect.setClipState(axes.getClipState());
75         rect.setMarkMode(axes.getMarkMode());
76
77         /*
78          * Initializes the contour properties (background, foreground, etc)
79          * to the default values (those of the parent Axes).
80          */
81         cloneGraphicContext(parentSubwin, iRect);
82
83         /* Contour settings */
84         rect.setLineMode(isline == 1);
85         rect.setFillMode(isfilled == 1);
86
87         if (foreground != -1) {
88             rect.setLineColor(foreground);
89         }
90
91         if (background != -1) {
92             rect.setBackground(background);
93         }
94
95         controller.objectCreated(iRect);
96
97         /*
98          * Sets the Axes as the rectangle's parent and adds the rectangle to
99          * its parent's list of children.
100          */
101         //setGraphicObjectRelationship(pparentsubwinUID, pobjUID);
102
103         return iRect;
104     }
105
106     public static int cloneGraphicContext(int sourceIdentifier, int destIdentifier) {
107         GraphicController controller = GraphicController.getController();
108         Boolean lineMode = false;
109         Integer foreground = 0;
110         Integer lineStyle = 0;
111         Integer background = 0;
112         Integer markForeground = 0;
113         Integer markBackground = 0;
114         Integer markStyle = 0;
115         Integer markSize = 0;
116         Integer markSizeUnit = 0;
117         Double lineThickness = 0.;
118
119         /*
120          * All these properties are passed by value thus do not care to release them
121          * and do not call releaseGraphicObjectProperty on purpose.
122          */
123
124         lineMode = (Boolean) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_MODE__);
125         foreground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__);
126         lineThickness = (Double) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__);
127         lineStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__);
128
129         background = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_BACKGROUND__);
130
131         markForeground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__);
132
133         markBackground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__);
134
135         markStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__);
136
137         markSize = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__);
138
139         markSizeUnit = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__);
140
141         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_MODE__, lineMode);
142         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
143         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__, lineThickness);
144         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__, lineStyle);
145
146         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_BACKGROUND__, background);
147
148         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__, markForeground);
149         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__, markBackground);
150         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__, markStyle);
151         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__, markSize);
152         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__, markSizeUnit);
153
154         return 0;
155     }
156
157     public static int cloneFontContext(int sourceIdentifier, int destIdentifier) {
158         GraphicController controller = GraphicController.getController();
159
160         Integer fontColor = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_COLOR__);
161         Integer fontStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_STYLE__);
162         Double fontSize = (Double) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_SIZE__);
163         Boolean fontFractional = (Boolean) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_FRACTIONAL__);
164
165         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_COLOR__, fontColor);
166         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_STYLE__, fontStyle);
167         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_SIZE__, fontSize);
168         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_FRACTIONAL__, fontFractional);
169
170         return 0;
171     }
172
173     public static int createHiddenLabel(int parent) {
174
175         GraphicController controller = GraphicController.getController();
176
177         Integer iLabel = controller.askObject(Type.LABEL, false);
178         Label label = (Label) controller.getObjectFromId(iLabel);
179
180         //Hide Label as they are non explicit children
181         label.setHidden(true);
182         label.setAutoPosition(true);
183         label.setAutoRotation(true);
184
185         cloneGraphicContext(parent, iLabel);
186         cloneFontContext(parent, iLabel);
187         controller.objectCreated(iLabel);
188
189         // Sets the label's parent
190         controller.setGraphicObjectRelationship(parent, iLabel);
191
192         return iLabel;
193     }
194
195     public static void initSubWinBounds(int subWin) {
196         GraphicController controller = GraphicController.getController();
197
198         controller.setProperty(subWin, GraphicObjectProperties.__GO_X_AXIS_LOG_FLAG__, false);
199         controller.setProperty(subWin, GraphicObjectProperties.__GO_Y_AXIS_LOG_FLAG__, false);
200         controller.setProperty(subWin, GraphicObjectProperties.__GO_Z_AXIS_LOG_FLAG__, false);
201     }
202
203     public static void reinitSubWin(int subWin) {
204         GraphicController controller = GraphicController.getController();
205         Integer label = 0;
206
207         for (Integer childId : (Integer[]) controller.getProperty(subWin, GraphicObjectProperties.__GO_CHILDREN__)) {
208             GraphicModel.getModel().deleteObject(childId);
209         }
210
211         label = createHiddenLabel(subWin);
212         controller.setProperty(subWin, GraphicObjectProperties.__GO_TITLE__, label);
213
214         label = createHiddenLabel(subWin);
215         controller.setProperty(subWin, GraphicObjectProperties.__GO_X_AXIS_LABEL__, label);
216
217         label = createHiddenLabel(subWin);
218         controller.setProperty(subWin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__, label);
219
220         label = createHiddenLabel(subWin);
221         controller.setProperty(subWin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__, label);
222
223         controller.setProperty(subWin, GraphicObjectProperties.__GO_X_AXIS_LOCATION__, 0);
224         controller.setProperty(subWin, GraphicObjectProperties.__GO_Y_AXIS_LOCATION__, 4);
225         controller.setProperty(subWin, GraphicObjectProperties.__GO_VISIBLE__, true);
226         controller.setProperty(subWin, GraphicObjectProperties.__GO_FIRST_PLOT__, true);
227
228         Integer axesModel = GraphicModel.getAxesModel().getIdentifier();
229         Axes axes = (Axes) controller.getObjectFromId(axesModel);
230
231         controller.setProperty(subWin, GraphicObjectProperties.__GO_VIEW__, axes.getView());
232         controller.setProperty(subWin, GraphicObjectProperties.__GO_ROTATION_ANGLES__, axes.getRotationAngles());
233         controller.setProperty(subWin, GraphicObjectProperties.__GO_ROTATION_ANGLES_3D__, axes.getRotationAngles3d());
234     }
235
236     public static boolean isAxesRedrawing(int subWin) {
237         GraphicController controller = GraphicController.getController();
238         Axes axes = (Axes)controller.getObjectFromId(subWin);
239
240         if (axes.getAutoClear()) {
241             reinitSubWin(subWin);
242             return true;
243         }
244         return false;
245     }
246
247     public static int createLabel(int parent, int type) {
248         GraphicController controller = GraphicController.getController();
249         Double[] position = new Double[3];
250         position[0] = 1.0;
251         position[1] = 1.0;
252         position[2] = 1.0;
253
254         //check parent type
255         Integer parentType = (Integer) controller.getProperty(parent, GraphicObjectProperties.__GO_TYPE__);
256         if (parentType != GraphicObjectProperties.__GO_AXES__) {
257             return 1;
258         }
259
260         //get axes model
261         Integer axesModel = GraphicModel.getAxesModel().getIdentifier();
262
263         //get type label from axes model
264         Integer labelSource = (Integer) controller.getProperty(axesModel, type);
265
266         //clone label
267         Integer newLabel = controller.cloneObject(labelSource);
268         controller.setProperty(newLabel, GraphicObjectProperties.__GO_POSITION__, position);
269         // Auto position must be reset as setting the position has set it to false
270         Boolean autoPosition = (Boolean ) controller.getProperty(labelSource, GraphicObjectProperties.__GO_AUTO_POSITION__);
271         controller.setProperty(newLabel, GraphicObjectProperties.__GO_AUTO_POSITION__, autoPosition);
272
273         // Set relation between newLabel and parent
274         controller.setProperty(parent, type, newLabel);
275         controller.setGraphicObjectRelationship(parent, newLabel);
276         return 0;
277     }
278
279     public final static int createFigureFromModel() {
280         GraphicController controller = GraphicController.getController();
281         return controller.cloneObject(GraphicModel.getFigureModel().getIdentifier());
282     }
283
284     public final static int cloneAxesModel(int parent) {
285         GraphicController controller = GraphicController.getController();
286
287         Integer newAxes = controller.cloneObject(GraphicModel.getAxesModel().getIdentifier());
288         createLabel(newAxes, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
289         createLabel(newAxes, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
290         createLabel(newAxes, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
291         createLabel(newAxes, GraphicObjectProperties.__GO_TITLE__);
292
293         controller.setGraphicObjectRelationship(parent, newAxes);
294         controller.setProperty(parent, GraphicObjectProperties.__GO_SELECTED_CHILD__, newAxes);
295
296         ScilabNativeView.ScilabNativeView__setCurrentSubWin(newAxes);
297         ScilabNativeView.ScilabNativeView__setCurrentObject(newAxes);
298         return newAxes;
299     }
300
301     public final static void cloneMenus(int iModel, int iParent) {
302         GraphicController controller = GraphicController.getController();
303         GraphicObject model = controller.getObjectFromId(iModel);
304
305         Integer[] children = model.getChildren();
306
307         for (int i = children.length - 1 ; i >= 0 ; i--) {
308             GraphicObject child = controller.getObjectFromId(children[i]);
309             if (child.getType() == GraphicObjectProperties.__GO_UIMENU__) {
310                 Integer newMenu = controller.cloneObject(children[i]);
311                 controller.setGraphicObjectRelationship(iParent, newMenu);
312
313                 cloneMenus(children[i], newMenu);
314             }
315         }
316     }
317
318     public final static int createFigure(boolean dockable, int menubarType, int toolbarType, boolean defaultAxes, boolean visible) {
319         GraphicController controller =  GraphicController.getController();
320         Integer figModel = GraphicModel.getFigureModel().getIdentifier();
321         Integer figId = controller.cloneObject(figModel, false);
322         Figure figure = (Figure) controller.getObjectFromId(figId);
323         figure.setDockable(dockable);
324         figure.setMenubar(menubarType);
325         figure.setToolbar(toolbarType);
326         figure.setVisible(visible);
327         figure.setDefaultAxes(defaultAxes);
328
329         controller.objectCreated(figId);
330         ScilabNativeView.ScilabNativeView__setCurrentFigure(figId);
331
332         if (menubarType == BarType.FIGURE.ordinal()) {
333             cloneMenus(figModel, figId);
334         }
335
336         if (defaultAxes) {
337             //clone default axes
338             cloneAxesModel(figId);
339         }
340
341         return figId;
342     }
343
344     public final static int createNewFigureWithAxes() {
345         GraphicController controller = GraphicController.getController();
346         Integer figModel  = GraphicModel.getFigureModel().getIdentifier();
347
348         //clone default figure
349         Integer newFigure = createFigureFromModel();
350
351         //Clone the default menus
352         cloneMenus(figModel, newFigure);
353
354         //set ID to 0
355         controller.setProperty(newFigure, GraphicObjectProperties.__GO_ID__, 0);
356
357         //clone default axes
358         cloneAxesModel(newFigure);
359         ScilabNativeView.ScilabNativeView__setCurrentFigure(newFigure);
360
361         //Force axes size after window creation
362         Integer[] axesSize = (Integer[]) controller.getProperty(figModel, GraphicObjectProperties.__GO_AXES_SIZE__);
363         controller.setProperty(newFigure, GraphicObjectProperties.__GO_AXES_SIZE__, axesSize);
364
365         controller.setProperty(newFigure, GraphicObjectProperties.__GO_VALID__, true);
366
367
368         return newFigure;
369     }
370
371     public final static int createSubWin(int parentFigure) {
372         //GraphicController controller = GraphicController.getController();
373         //GraphicObject parent = controller.getObjectFromId(parentFigure);
374         //if (parent.getType() != GraphicObjectProperties.__GO_FIGURE__) {
375         //    return 0;
376         //}
377
378         return cloneAxesModel(parentFigure);
379     }
380
381     public final static int createText(int iParentsubwinUID, String[] str, int nbRow, int nbCol,
382                                        double x, double y, boolean autoSize, double[] userSize, int centerPos,
383                                        int foreground, boolean isForeground, int background, boolean isBackground,
384                                        boolean isBoxed, boolean isLine,
385                                        boolean isFilled, int align) {
386
387         GraphicController controller = GraphicController.getController();
388         int iText = controller.askObject(Type.TEXT, false);
389
390         Axes axes = (Axes) controller.getObjectFromId(iParentsubwinUID);
391         Text text = (Text) controller.getObjectFromId(iText);
392
393         //clip
394         text.setClipBox(axes.getClipBox());
395         text.setClipBoxSet(axes.getClipBoxSet());
396         text.setClipState(axes.getClipState());
397
398         //text
399         Integer[] dimensions = new Integer[2];
400         dimensions[0] = nbRow;
401         dimensions[1] = nbCol;
402         text.setTextArrayDimensions(dimensions);
403         text.setTextStrings(str);
404
405         //position
406         Double[] position = new Double[3];
407         position[0] = x;
408         position[1] = y;
409         position[2] = 0.0;
410         text.setPosition(position);
411
412         //test box
413         Double[] setUserSize = new Double[2];
414         text.setTextBoxMode(centerPos);
415         text.setAutoDimensioning(autoSize);
416
417         if (autoSize == false || centerPos != 0) {
418             setUserSize[0] = userSize[0];
419             setUserSize[1] = userSize[1];
420         } else {
421             setUserSize[0] = 0.0;
422             setUserSize[1] = 0.0;
423         }
424         text.setTextBox(setUserSize);
425
426         int alignment = align - 1;
427         if (alignment < 0 || alignment > 2) {
428             alignment = 0;
429         }
430
431         text.setAlignment(alignment);
432
433         cloneGraphicContext(iParentsubwinUID, iText);
434         cloneFontContext(iParentsubwinUID, iText);
435
436         text.setBox(isBoxed);
437         text.setLineMode(isLine);
438         text.setFillMode(isFilled);
439
440         if (isForeground) {
441             text.setLineColor(foreground);
442         }
443
444         if (isBackground) {
445             text.setBackground(background);
446         }
447
448         text.setVisible(axes.getVisible());
449         controller.objectCreated(iText);
450         return iText;
451     }
452
453     public final static int createArc(int parent, double x, double y, double h, double w,
454                                       double startAngle, double endAngle,
455                                       int foreground, boolean isForeground, int background, boolean isBackground,
456                                       boolean filled, boolean line) {
457
458         GraphicController controller = GraphicController.getController();
459         int iArc = controller.askObject(Type.ARC, false);
460
461         Axes axes = (Axes) controller.getObjectFromId(parent);
462         Arc arc = (Arc) controller.getObjectFromId(iArc);
463
464         //set visible false during construction
465         arc.setVisible(false);
466
467         Double[] upperLeftPoint = new Double[3];
468         upperLeftPoint[0] = x;
469         upperLeftPoint[1] = y;
470         upperLeftPoint[2] = 0.0;
471
472         arc.setUpperLeftPoint(upperLeftPoint);
473         arc.setHeight(h);
474         arc.setWidth(w);
475         arc.setStartAngle(startAngle);
476         arc.setEndAngle(endAngle);
477         arc.setArcDrawingMethod(axes.getArcDrawingMethod());
478
479         //clip
480         arc.setClipBox(axes.getClipBox());
481         arc.setClipBoxSet(axes.getClipBoxSet());
482         arc.setClipState(axes.getClipState());
483
484         cloneGraphicContext(parent, iArc);
485
486         arc.setLineMode(line);
487         arc.setFillMode(filled);
488
489         if (isForeground) {
490             arc.setLineColor(foreground);
491         }
492
493         if (isBackground) {
494             arc.setBackground(background);
495         }
496
497         arc.setVisible(axes.getVisible());
498         controller.objectCreated(iArc);
499         controller.setGraphicObjectRelationship(parent, iArc);
500         return iArc;
501     }
502
503     public final static int createAxis(int parent, int dir, int tics, double[] vx, double[] vy, int subint, String format,
504                                        int fontSize, int textColor, int ticsColor, boolean seg) {
505
506         GraphicController controller = GraphicController.getController();
507         int iAxis = controller.askObject(Type.AXIS, false);
508
509         Axes axes = (Axes) controller.getObjectFromId(parent);
510         Axis axis = (Axis) controller.getObjectFromId(iAxis);
511
512         //clip box
513         axis.setClipBox(axes.getClipBox());
514         axis.setClipBoxSet(false);
515
516         axis.setTicksDirection(dir);
517         axis.setTicksStyle(tics);
518
519         axis.setXTicksCoords(toDouble(vx));
520         axis.setYTicksCoords(toDouble(vy));
521
522         if (format != null && format.equals("") == false) {
523             axis.setFormatn(format);
524         }
525
526         axis.setSubticks(subint);
527         axis.setTicksSegment(seg);
528         cloneGraphicContext(parent, iAxis);
529         cloneFontContext(parent, iAxis);
530
531         Font font = axis.getFont();
532         font.setSize(new Double(fontSize));
533         font.setColor(textColor);
534         axis.setTicksColor(ticsColor);
535
536         controller.objectCreated(iAxis);
537         controller.setGraphicObjectRelationship(parent, iAxis);
538         return iAxis;
539     }
540
541     public static int createCompound(int parent, int[] children) {
542         GraphicController controller = GraphicController.getController();
543         int iCompound = controller.askObject(Type.COMPOUND);
544
545         GraphicObject obj = controller.getObjectFromId(parent);
546         for (int i = 0 ; i < children.length ; i++) {
547             controller.setGraphicObjectRelationship(iCompound, children[i]);
548         }
549
550         controller.setGraphicObjectRelationship(parent, iCompound);
551         controller.setProperty(iCompound, GraphicObjectProperties.__GO_VISIBLE__, obj.getVisible());
552         return iCompound;
553     }
554
555     public static int createCompoundSeq(int parent, int childrenCount) {
556         GraphicController controller = GraphicController.getController();
557         int iCompound = controller.askObject(Type.COMPOUND);
558         GraphicObject axes = controller.getObjectFromId(parent);
559
560         Integer[] children = axes.getChildren();
561
562         /*
563          * Remove the last "number" created objects (located at the children list's head)
564          * and add them to the compound in the same order
565          */
566         for (int i = 0 ; i < childrenCount ; i++) {
567             /*
568              * Set the parent-child relationship between the Compound and each aggregated object.
569              * Children are added to the Compound from the least recent to the most recent, to
570              * preserve their former ordering.
571              */
572             controller.setGraphicObjectRelationship(iCompound, children[childrenCount - i - 1]);
573         }
574
575         controller.setGraphicObjectRelationship(parent, iCompound);
576
577         /*
578          * visibility is obtained from the parent Figure, whereas it is retrieved from the
579          * parent Axes in ConstructCompound.
580          * To be made consistent.
581          */
582         Figure fig = (Figure)controller.getObjectFromId(axes.getParentFigure());
583         controller.setProperty(iCompound, GraphicObjectProperties.__GO_VISIBLE__, fig.getVisible());
584         return iCompound;
585     }
586
587     public static int createFec(int parent, double[] zminmax, int[] colminmax, int[] colout, boolean with_mesh) {
588
589         GraphicController controller = GraphicController.getController();
590         int iFec = controller.askObject(Type.FEC, false);
591         Axes axes = (Axes) controller.getObjectFromId(parent);
592         Fec fec = (Fec) controller.getObjectFromId(iFec);
593
594
595         fec.setZBounds(toDouble(zminmax));
596         fec.setColorRange(toInteger(colminmax));
597         fec.setOutsideColor(toInteger(colout));
598
599         fec.setVisible(axes.getVisible());
600
601         //clip box
602         fec.setClipBox(axes.getClipBox());
603         fec.setClipBoxSet(axes.getClipBoxSet());
604         fec.setClipState(axes.getClipState());
605
606         cloneGraphicContext(parent, iFec);
607
608         fec.setLineMode(with_mesh);
609
610         controller.objectCreated(iFec);
611         return iFec;
612     }
613
614     public static int createGrayplot(int parent, int type, double[] pvecx, int n1, int n2) {
615
616         int[] objectTypes = new int[] {GraphicObjectProperties.__GO_GRAYPLOT__, GraphicObjectProperties.__GO_MATPLOT__, GraphicObjectProperties.__GO_MATPLOT__};
617
618         GraphicController controller = GraphicController.getController();
619         int iPlot = controller.askObject(GraphicObject.getTypeFromName(objectTypes[type]), false);
620         Axes axes = (Axes) controller.getObjectFromId(parent);
621         Imageplot plot = (Imageplot) controller.getObjectFromId(iPlot);
622
623         if (type == 2) { //Matplot1
624             Double[] data = new Double[pvecx.length];
625             for (int i = 0 ; i < pvecx.length ; i++) {
626                 data[i] = pvecx[i];
627             }
628             plot.setTranslate(data);
629
630             Double[] scale = new Double[2];
631             scale[0] = (pvecx[2] - pvecx[0]) / (n2 - 1.0);
632             scale[1] = (pvecx[3] - pvecx[1]) / (n1 - 1.0);
633             plot.setScale(scale);
634         }
635
636         plot.setVisible(axes.getVisible());
637
638         //clip box
639         plot.setClipBox(axes.getClipBox());
640         plot.setClipBoxSet(axes.getClipBoxSet());
641         plot.setClipState(axes.getClipState());
642
643         cloneGraphicContext(parent, iPlot);
644         controller.objectCreated(iPlot);
645         return iPlot;
646     }
647
648
649     public static int createPolyline(int parent, boolean closed, int plot,
650                                      int foreground, boolean isForeground, int[] background, int mark_style, boolean isMarkStyle,
651                                      int mark_foreground, boolean isMarkForeground,
652                                      int mark_background, boolean isMarkBackground,
653                                      boolean isline, boolean isfilled, boolean ismark, boolean isinterp) {
654
655         GraphicController controller = GraphicController.getController();
656         int iPoly = controller.askObject(Type.POLYLINE, false);
657         Axes axes = (Axes) controller.getObjectFromId(parent);
658         Polyline poly = (Polyline) controller.getObjectFromId(iPoly);
659
660         poly.setVisible(false);
661
662         //clip box
663         poly.setClipBox(axes.getClipBox());
664         poly.setClipBoxSet(axes.getClipBoxSet());
665         poly.setClipState(axes.getClipState());
666
667         poly.setClosed(closed);
668         poly.setPolylineStyle(plot);
669
670         cloneGraphicContext(parent, iPoly);
671
672         poly.setMarkMode(ismark);
673         poly.setLineMode(isline);
674         poly.setFillMode(isfilled);
675         poly.setInterpColorMode(isinterp);
676
677         if (isForeground) {
678             poly.setLineColor(foreground);
679         }
680
681         if (background.length != 0) {
682             if (isinterp) {
683                 /* 3 or 4 values to store */
684                 Integer[] color = new Integer[background.length];
685                 for (int i = 0 ; i < background.length ; i++) {
686                     color[i] = background[i];
687                 }
688
689                 poly.setInterpColorVector(color);
690             } else {
691                 poly.setBackground(background[0]);
692             }
693         }
694
695         if (isMarkStyle) {
696             poly.setMarkStyle(mark_style);
697         }
698
699         if (isMarkForeground) {
700             poly.setMarkForeground(mark_foreground);
701         }
702
703         if (isMarkBackground) {
704             poly.setMarkBackground(mark_background);
705         }
706
707         poly.setVisible(true);
708         controller.objectCreated(iPoly);
709         return iPoly;
710     }
711
712     public static int createLegend(int parent, String[] text, int[] handles) {
713         GraphicController controller = GraphicController.getController();
714         Axes axes = (Axes) controller.getObjectFromId(parent);
715
716         if (axes.getHasLegendChild()) {
717             controller.removeRelationShipAndDelete(axes.getLegendChild());
718         }
719
720
721         int iLeg = controller.askObject(Type.LEGEND, false);
722         Legend leg = (Legend)controller.getObjectFromId(iLeg);
723
724         leg.setParent(parent);
725         leg.setVisible(axes.getVisible());
726
727         int count = handles.length;
728         Integer[] textDims = new Integer[2];
729         textDims[0] = count;
730         textDims[1] = 1;
731
732         leg.setTextArrayDimensions(textDims);
733         leg.setTextStrings(text);
734
735         /*
736          * Links are ordered from most recent to least recent,
737          * as their referred-to Polylines in the latter's parent Compound object.
738          */
739
740         ArrayList<Integer> links = new ArrayList<Integer>();
741         for (int i = count - 1 ; i >= 0 ; i--) {
742             links.add(count - i - 1, handles[i]);
743         }
744
745         leg.setLinks(links);
746
747         leg.setClipBoxSet(false);
748         leg.setClipState(0); //OFF
749         leg.setClipBox(axes.getClipBox());
750
751         cloneGraphicContext(parent,  iLeg);
752         cloneFontContext(parent, iLeg);
753
754         leg.setFillMode(true);
755
756         controller.objectCreated(iLeg);
757         leg.setParent(0);
758         controller.setGraphicObjectRelationship(parent, iLeg);
759         return iLeg;
760     }
761
762     public static int createSegs(int parent, double[] vx, double[] vy, double[] vz, boolean isVZ,
763                                  int[] style, double arsize) {
764         GraphicController controller = GraphicController.getController();
765         Axes axes = (Axes) controller.getObjectFromId(parent);
766         int iSegs = controller.askObject(Type.SEGS, false);
767         Segs segs = (Segs)controller.getObjectFromId(iSegs);
768
769         segs.setVisible(axes.getVisible());
770
771         //clip box
772         segs.setClipBox(axes.getClipBox());
773         segs.setClipBoxSet(axes.getClipBoxSet());
774         segs.setClipState(axes.getClipState());
775
776         /* Segs: Nbr1/2 arrows, Nbr1 is the number of endpoints */
777         int numberArrows = vx.length / 2;
778
779         segs.setNumberArrows(numberArrows);
780         segs.setArrowSize(arsize);
781
782         Double[] arrowCoords = new Double[3 * numberArrows];
783         for (int i = 0 ; i < numberArrows ; i++) {
784             arrowCoords[3 * i] = vx[2 * i];
785             arrowCoords[3 * i + 1] = vy[2 * i];
786             if (isVZ) {
787                 arrowCoords[3 * i + 2] = vz[2 * i];
788             } else {
789                 arrowCoords[3 * i + 2] = 0.0;
790             }
791         }
792
793         segs.setBase(arrowCoords);
794
795         for (int i = 0 ; i < numberArrows ; i++) {
796             arrowCoords[3 * i] = vx[2 * i + 1];
797             arrowCoords[3 * i + 1] = vy[2 * i + 1];
798             if (isVZ) {
799                 arrowCoords[3 * i + 2] = vz[2 * i + 1];
800             } else {
801                 arrowCoords[3 * i + 2] = 0.0;
802             }
803         }
804
805         segs.setDirection(arrowCoords);
806         segs.setColors(toInteger(style));
807
808         cloneGraphicContext(parent, iSegs);
809         controller.objectCreated(iSegs);
810         controller.setGraphicObjectRelationship(parent, iSegs);
811         return iSegs;
812     }
813
814     public static int createChamp(int parent, double[] vx, double[] vy,
815                                   double[] vfx, double[] vfy, double arsize, boolean typeofchamp) {
816
817         GraphicController controller = GraphicController.getController();
818         Axes axes = (Axes) controller.getObjectFromId(parent);
819
820         int iChamp = controller.askObject(Type.CHAMP, false);
821         Champ champ = (Champ)controller.getObjectFromId(iChamp);
822
823         champ.setVisible(axes.getVisible());
824
825         //clip box
826         champ.setClipBox(axes.getClipBox());
827         champ.setClipBoxSet(axes.getClipBoxSet());
828         champ.setClipState(axes.getClipState());
829
830         int numberArrows = vx.length * vy.length;
831         champ.setNumberArrows(numberArrows);
832
833         Integer[] dimensions = new Integer[] {vx.length, vy.length};
834         champ.setDimensions(dimensions);
835
836         champ.setArrowSize(arsize);
837
838         Double[] arrowCoords = new Double[3 * numberArrows];
839
840         //convert vx Double
841         Double[] temp = new Double[vx.length];
842         for (int i =  0 ; i < vx.length ; i++) {
843             temp[i] = vx[i];
844         }
845         champ.setBaseX(temp);
846
847         //convert vy Double
848         temp = new Double[vy.length];
849         for (int i =  0 ; i < vy.length ; i++) {
850             temp[i] = vy[i];
851         }
852         champ.setBaseY(temp);
853
854         for (int i = 0 ; i < numberArrows ; i++) {
855             arrowCoords[3 * i] = vfx[i];
856             arrowCoords[3 * i + 1] = vfy[i];
857             arrowCoords[3 * i + 2] = 0.0;
858         }
859
860         champ.setDirection(arrowCoords);
861         champ.setColored(typeofchamp);
862
863         cloneGraphicContext(parent, iChamp);
864
865         controller.objectCreated(iChamp);
866         controller.setGraphicObjectRelationship(parent, iChamp);
867
868         return iChamp;
869     }
870
871     public static int createSurface(int parent, int typeof3d, int colorFlag, int colorMode) {
872         GraphicController controller = GraphicController.getController();
873         Axes axes = (Axes) controller.getObjectFromId(parent);
874
875         int iSurf = controller.askObject(GraphicObject.getTypeFromName(typeof3d), false);
876         Surface surf = (Surface) controller.getObjectFromId(iSurf);
877
878         surf.setVisible(axes.getVisible());
879
880         //clip box
881         surf.setClipBox(axes.getClipBox());
882         surf.setClipBoxSet(axes.getClipBoxSet());
883         surf.setClipState(axes.getClipState());
884
885         surf.setColorFlag(colorFlag);
886         surf.setColorMode(colorMode);
887
888         surf.setHiddenColor(axes.getHiddenColor());
889
890         surf.setSurfaceMode(true);
891         cloneGraphicContext(parent, iSurf);
892         controller.objectCreated(iSurf);
893         controller.setGraphicObjectRelationship(parent, iSurf);
894
895         return iSurf;
896     }
897
898     public static void initSubWinTo3d(int iSubwin, String legend, boolean isLegend,
899                                       int[] flag, double alpha, double theta,
900                                       double[] ebox, double[] x, double[] y, double[] z) {
901         GraphicController controller = GraphicController.getController();
902
903         // Force 3d view
904         controller.setProperty(iSubwin, GraphicObjectProperties.__GO_VIEW__, 1);
905
906         if (isLegend) {
907             StringTokenizer strTok =  new StringTokenizer(legend, "@");
908             int iToken = strTok.countTokens();
909             if (iToken > 0) {
910                 //X
911                 String str[] = new String[] {strTok.nextToken()};
912                 Integer label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
913                 Integer[] dims = new Integer[] {1, 1};
914                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_ARRAY_DIMENSIONS__, dims);
915                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_STRINGS__, str);
916             }
917
918             if (iToken > 1) {
919                 //Y
920                 String str[] = new String[] {strTok.nextToken()};
921                 Integer label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
922                 Integer[] dims = new Integer[] {1, 1};
923                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_ARRAY_DIMENSIONS__, dims);
924                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_STRINGS__, str);
925             }
926
927             if (iToken > 2) {
928                 //Z
929                 String str[] = new String[] {strTok.nextToken()};
930                 Integer label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
931                 Integer[] dims = new Integer[] {1, 1};
932                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_ARRAY_DIMENSIONS__, dims);
933                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_STRINGS__, str);
934             }
935         }
936
937         // Force psubwin->logflags to linear
938         controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LOG_FLAG__, false);
939         controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LOG_FLAG__, false);
940         controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LOG_FLAG__, false);
941
942         Boolean firstPlot = (Boolean) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_FIRST_PLOT__);
943
944         if (firstPlot && (flag[2] == 0 || flag[2] == 1)) {
945             /* Nothing to do */
946         } else {
947             if (flag[2] == 0 || flag[2] == 1) {
948                 if (firstPlot) {
949                     controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, false);
950                     controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, false);
951                     controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, false);
952
953                     // 0: OFF
954                     controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 0);
955
956                     Integer label = 0;
957                     label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
958                     controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
959                     label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
960                     controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
961                     label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
962                     controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
963                 }
964             } else if (flag[2] == 2) {
965                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, false);
966                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, false);
967                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, false);
968
969                 //2: HIDDEN_AXES
970                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 2);
971
972                 Integer label = 0;
973                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
974                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
975                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
976                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
977                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
978                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
979
980             } else if (flag[2] == 3) {
981                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, false);
982                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, false);
983                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, false);
984
985                 //1: ON
986                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 1);
987
988                 Integer label = 0;
989                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
990                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
991                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
992                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
993                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
994                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
995
996             } else if (flag[2] == 4) {
997                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, true);
998                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, true);
999                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, true);
1000
1001                 //1: ON
1002                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 1);
1003
1004                 Integer label = 0;
1005                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
1006                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
1007                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
1008                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
1009                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
1010                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
1011             }
1012         }
1013
1014         Double[] rotationAngles = new Double[] {alpha, theta};
1015         controller.setProperty(iSubwin, GraphicObjectProperties.__GO_ROTATION_ANGLES__, rotationAngles);
1016
1017         Double[] dataBounds = (Double[]) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_DATA_BOUNDS__);
1018         Boolean autoScale = (Boolean) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_AUTO_SCALE__);
1019
1020         Double rect[] = new Double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
1021         if (autoScale) {
1022             // compute and merge new specified bounds with data bounds
1023             switch (flag[1]) {
1024                 case 0 :
1025                     break;
1026                 case 1 :
1027                 case 3 :
1028                 case 5 :
1029                 case 7 :
1030                     rect[0] = ebox[0]; // xmin
1031                     rect[1] = ebox[1]; // xmax
1032                     rect[2] = ebox[2]; // ymin
1033                     rect[3] = ebox[3]; // ymax
1034                     rect[4] = ebox[4]; // zmin
1035                     rect[5] = ebox[5]; // zmax
1036                     break;
1037                 case 2 :
1038                 case 4 :
1039                 case 6 :
1040                 case 8 :
1041                     double[] res = getDrect(x, rect[0], rect[1], dataBounds[0], dataBounds[1]);
1042                     rect[0] = res[0];
1043                     rect[1] = res[1];
1044
1045                     res = getDrect(y, rect[2], rect[3], dataBounds[2], dataBounds[3]);
1046                     rect[2] = res[0];
1047                     rect[3] = res[1];
1048
1049                     res = getDrect(z, rect[4], rect[5], dataBounds[4], dataBounds[5]);
1050                     rect[4] = res[0];
1051                     rect[5] = res[1];
1052                     break;
1053             }
1054
1055             if (firstPlot == false) {
1056                 rect[0] = Math.min(dataBounds[0], rect[0]); // xmin
1057                 rect[1] = Math.max(dataBounds[1], rect[1]); // xmax
1058                 rect[2] = Math.min(dataBounds[2], rect[2]); // ymin
1059                 rect[3] = Math.max(dataBounds[3], rect[3]); // ymax
1060                 rect[4] = Math.min(dataBounds[4], rect[4]); // zmin
1061                 rect[5] = Math.max(dataBounds[5], rect[5]); // zmax
1062             }
1063
1064             if (flag[1] != 0) {
1065                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_DATA_BOUNDS__, rect);
1066             }
1067         }
1068
1069         if (flag[1] != 0) {
1070             boolean isoview = (flag[1] == 3 || flag[1] == 4 || flag[1] == 5 || flag[1] == 6);
1071             controller.setProperty(iSubwin, GraphicObjectProperties.__GO_ISOVIEW__, isoview);
1072         }
1073     }
1074
1075     private static double[] getDrect(double[] x, double min, double max, double defaultMin, double defaultMax) {
1076         double refMax = Double.NEGATIVE_INFINITY;
1077         double refMin = Double.POSITIVE_INFINITY;
1078         boolean isInfinite = true;
1079
1080         for (int i = 0 ; i < x.length ; i++) {
1081             Double tmp = x[i];
1082             if (tmp.isInfinite() == false && tmp.isNaN() == false) {
1083                 refMin = Math.min(refMin, tmp);
1084                 refMax = Math.max(refMax, tmp);
1085                 isInfinite = false;
1086             }
1087         }
1088
1089         if (isInfinite) {
1090             refMin = defaultMin;
1091             refMax = defaultMax;
1092         }
1093
1094         return new double[] {refMin, refMax};
1095     }
1096
1097     private static boolean  isValidType(int type) {
1098         return type >= 0 && type <= 1;
1099     }
1100
1101     private static boolean isValidColor(double[] color) {
1102         return (color[0] >= 0.0 && color[0] <= 1.0)
1103                && (color[1] >= 0.0 && color[1] <= 1.0)
1104                && (color[2] >= 0.0 && color[2] <= 1.0);
1105     }
1106
1107     public static int createLight(int parent, int type, boolean visible, double[] pos,
1108                                   double[] dir, double[] ambient, double[] diffuse, double[] specular) {
1109         GraphicController controller = GraphicController.getController();
1110
1111         int iLight = controller.askObject(Type.LIGHT, false);
1112         Light light = (Light) controller.getObjectFromId(iLight);
1113
1114         light.setVisible(visible);
1115         if (isValidType(type)) {
1116             light.setLightType(LightType.intToEnum(type));
1117         }
1118
1119         if (pos.length == 3) {
1120             light.setPosition(toDouble(pos));
1121         }
1122
1123         if (dir.length == 3) {
1124             light.setDirection(toDouble(dir));
1125         }
1126         if (ambient.length == 3) {
1127             if (isValidColor(ambient)) {
1128                 light.setAmbientColor(toDouble(ambient));
1129             }
1130         }
1131         if (diffuse.length == 3) {
1132             if (isValidColor(diffuse)) {
1133                 light.setDiffuseColor(toDouble(diffuse));
1134             }
1135         }
1136         if (specular.length == 3) {
1137             if (isValidColor(specular)) {
1138                 light.setSpecularColor(toDouble(specular));
1139             }
1140         }
1141
1142         controller.objectCreated(iLight);
1143         // Set light's parent
1144         controller.setGraphicObjectRelationship(parent, iLight);
1145         return iLight;
1146     }
1147
1148     private static Double[] toDouble(double[] var) {
1149         Double[] ret = new Double[var.length];
1150         for (int i = 0 ; i < var.length ; i++) {
1151             ret[i] = var[i];
1152         }
1153
1154         return ret;
1155     }
1156
1157     private static Integer[] toInteger(int[] var) {
1158         Integer[] ret = new Integer[var.length];
1159         for (int i = 0 ; i < var.length ; i++) {
1160             ret[i] = var[i];
1161         }
1162
1163         return ret;
1164     }
1165 }
1166