2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007-2008 - INRIA - Vincent COUVERT
4 * Copyright (C) 2008 - DIGITEO - Sylvestre KOUMAR
5 * Copyright (C) 2010 - DIGITEO - Manuel JULIACHS
6 * Copyright (C) 2010-2011 - DIGITEO - Vincent COUVERT
8 * This file must be used under the terms of the CeCILL.
9 * This source file is licensed as described in the file COPYING, which
10 * you should have received as part of this distribution. The terms
11 * are also available at
12 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
17 package org.scilab.modules.gui.bridge;
19 import java.awt.Color;
21 import java.awt.Image;
22 import java.awt.Toolkit;
23 import java.awt.datatransfer.Clipboard;
24 import java.awt.datatransfer.DataFlavor;
25 import java.awt.datatransfer.StringSelection;
26 import java.awt.datatransfer.Transferable;
27 import java.awt.datatransfer.UnsupportedFlavorException;
28 import java.awt.print.PrinterJob;
30 import java.io.FileInputStream;
31 import java.io.FileNotFoundException;
32 import java.io.IOException;
34 import javax.print.Doc;
35 import javax.print.DocFlavor;
36 import javax.print.DocPrintJob;
37 import javax.print.PrintException;
38 import javax.print.PrintService;
39 import javax.print.SimpleDoc;
40 import javax.print.attribute.HashPrintRequestAttributeSet;
41 import javax.print.attribute.PrintRequestAttribute;
42 import javax.print.attribute.PrintRequestAttributeSet;
43 import javax.print.attribute.standard.OrientationRequested;
44 import javax.swing.JEditorPane;
45 import javax.swing.JTextPane;
46 import javax.swing.text.BadLocationException;
47 import javax.swing.text.Document;
49 import org.scilab.modules.commons.ScilabCommons;
50 import org.scilab.modules.console.SciConsole;
51 import org.scilab.modules.graphic_export.FileExporter;
52 import org.scilab.modules.graphic_objects.figure.Figure;
53 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
54 import org.scilab.modules.gui.SwingView;
55 import org.scilab.modules.gui.SwingViewObject;
56 import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvas;
57 import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvasImpl;
58 import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
59 import org.scilab.modules.gui.bridge.contextmenu.SwingScilabContextMenu;
60 import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
61 import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
62 import org.scilab.modules.gui.checkbox.CheckBox;
63 import org.scilab.modules.gui.checkbox.ScilabCheckBox;
64 import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
65 import org.scilab.modules.gui.colorchooser.ColorChooser;
66 import org.scilab.modules.gui.colorchooser.ScilabColorChooser;
67 import org.scilab.modules.gui.console.ScilabConsole;
68 import org.scilab.modules.gui.contextmenu.ContextMenu;
69 import org.scilab.modules.gui.contextmenu.ScilabContextMenu;
70 import org.scilab.modules.gui.editbox.EditBox;
71 import org.scilab.modules.gui.editbox.ScilabEditBox;
72 import org.scilab.modules.gui.filechooser.FileChooser;
73 import org.scilab.modules.gui.filechooser.ScilabFileChooser;
74 import org.scilab.modules.gui.fontchooser.FontChooser;
75 import org.scilab.modules.gui.fontchooser.ScilabFontChooser;
76 import org.scilab.modules.gui.frame.Frame;
77 import org.scilab.modules.gui.frame.ScilabFrame;
78 import org.scilab.modules.gui.helpbrowser.HelpBrowser;
79 import org.scilab.modules.gui.helpbrowser.ScilabHelpBrowser;
80 import org.scilab.modules.gui.label.Label;
81 import org.scilab.modules.gui.label.ScilabLabel;
82 import org.scilab.modules.gui.listbox.ListBox;
83 import org.scilab.modules.gui.listbox.ScilabListBox;
84 import org.scilab.modules.gui.menu.Menu;
85 import org.scilab.modules.gui.menu.ScilabMenu;
86 import org.scilab.modules.gui.menubar.MenuBar;
87 import org.scilab.modules.gui.menubar.ScilabMenuBar;
88 import org.scilab.modules.gui.menuitem.MenuItem;
89 import org.scilab.modules.gui.menuitem.ScilabMenuItem;
90 import org.scilab.modules.gui.messagebox.MessageBox;
91 import org.scilab.modules.gui.messagebox.ScilabMessageBox;
92 import org.scilab.modules.gui.popupmenu.PopupMenu;
93 import org.scilab.modules.gui.popupmenu.ScilabPopupMenu;
94 import org.scilab.modules.gui.pushbutton.PushButton;
95 import org.scilab.modules.gui.pushbutton.ScilabPushButton;
96 import org.scilab.modules.gui.radiobutton.RadioButton;
97 import org.scilab.modules.gui.radiobutton.ScilabRadioButton;
98 import org.scilab.modules.gui.slider.ScilabSlider;
99 import org.scilab.modules.gui.slider.Slider;
100 import org.scilab.modules.gui.tab.ScilabTab;
101 import org.scilab.modules.gui.tab.Tab;
102 import org.scilab.modules.gui.textbox.ScilabTextBox;
103 import org.scilab.modules.gui.textbox.TextBox;
104 import org.scilab.modules.gui.toolbar.ToolBar;
105 import org.scilab.modules.gui.uidisplaytree.ScilabUiDisplayTree;
106 import org.scilab.modules.gui.uidisplaytree.UiDisplayTree;
107 import org.scilab.modules.gui.uitable.ScilabUiTable;
108 import org.scilab.modules.gui.uitable.UiTable;
109 import org.scilab.modules.gui.utils.BarUpdater;
110 import org.scilab.modules.gui.utils.ClosingOperationsManager;
111 import org.scilab.modules.gui.utils.ConfigManager;
112 import org.scilab.modules.gui.utils.ImageExporter;
113 import org.scilab.modules.gui.utils.Position;
114 import org.scilab.modules.gui.utils.PrinterHelper;
115 import org.scilab.modules.gui.utils.ScilabAboutBox;
116 import org.scilab.modules.gui.utils.ScilabPrint;
117 import org.scilab.modules.gui.utils.ScilabRelief;
118 import org.scilab.modules.gui.utils.Size;
119 import org.scilab.modules.gui.utils.UIElementMapper;
120 import org.scilab.modules.gui.utils.WebBrowser;
121 import org.scilab.modules.gui.waitbar.WaitBar;
122 import org.scilab.modules.gui.widget.Widget;
123 import org.scilab.modules.gui.window.ScilabWindow;
124 import org.scilab.modules.gui.window.Window;
125 import org.scilab.modules.localization.Messages;
128 * This class is used to call Scilab GUIs objects from Scilab
129 * @author Vincent COUVERT
131 public class CallScilabBridge {
133 private static final int NB_COLORS = 3;
135 private static final int POSITION_SIZE = 4;
137 private static final int X_INDEX = 0;
138 private static final int Y_INDEX = 1;
139 private static final int WIDTH_INDEX = 2;
140 private static final int HEIGHT_INDEX = 3;
142 private static final String NORMALFONT = "normal";
143 private static final String OBLIQUEFONT = "oblique";
144 private static final String ITALICFONT = "italic";
145 private static final String BOLDFONT = "bold";
146 private static final int DEFAULTFONTSIZE = 10;
147 private static final String DEFAULTFONTNAME = "helvetica";
149 private static final double DEFAULT_RED_BACKGROUND = 0.8 * 255;
150 private static final double DEFAULT_GREEN_BACKGROUND = 0.8 * 255;
151 private static final double DEFAULT_BLUE_BACKGROUND = 0.8 * 255;
153 private static final double BUTTON_RED_BACKGROUND = 0.6 * 255;
154 private static final double BUTTON_GREEN_BACKGROUND = 0.6 * 255;
155 private static final double BUTTON_BLUE_BACKGROUND = 0.6 * 255;
157 private static final double DEFAULT_RED_FOREGROUND = 0;
158 private static final double DEFAULT_GREEN_FOREGROUND = 0;
159 private static final double DEFAULT_BLUE_FOREGROUND = 0;
162 private static PrintRequestAttributeSet scilabPageFormat = new HashPrintRequestAttributeSet();
164 private static final String FIGURE_TITLE = "Graphic window number ";
166 private static final String CONSOLE = "Console";
171 protected CallScilabBridge() {
172 throw new UnsupportedOperationException(); /* Prevents calls from subclass */
182 * Read a line from the Console
183 * @return the line read
185 public static String readLine() {
186 return ScilabConsole.getConsole().readLine();
190 * Display a line in the Console
191 * @param dataToDisplay the line to display
193 public static void display(String dataToDisplay) {
194 ScilabConsole.getConsole().display(dataToDisplay);
198 * Get the status of the Console
199 * @return true if the console is at the prompt
201 public static boolean isWaitingForInput() {
202 return ScilabConsole.getConsole().isWaitingForInput();
206 * Update the number of lines and columns that Scilab use to format data to display
208 public static void scilabLinesUpdate() {
209 ScilabConsole.getConsole().scilabLinesUpdate();
215 public static void clear() {
216 ScilabConsole.getConsole().clear();
220 * Clear some lines in the Console
221 * @param nbLines the number of lines to clear
223 public static void clear(int nbLines) {
224 ScilabConsole.getConsole().clear(nbLines);
228 * Get a char to know if the user wants more data to be displayed
229 * @return the user answer
231 public static int getCharWithoutOutput() {
232 return ScilabConsole.getConsole().getAsSimpleConsole().getCharWithoutOutput();
236 * Put the prompt on the top left corner
238 public static void toHome() {
239 ScilabConsole.getConsole().toHome();
243 * Set the contents of the prompt
244 * @param prompt the content to set (default is -->)
246 public static void setPrompt(String prompt) {
247 ScilabConsole.getConsole().setPrompt(prompt);
251 * Clear the commands history
253 public static void clearHistory() {
254 ScilabConsole.getConsole().clearHistory();
257 /**************************/
259 /* OBJECT CREATION BRIDGE */
261 /**************************/
264 * Create a new Window in Scilab GUIs
265 * @return the ID of the window in the UIElementMapper
267 // TODO REMOVE ME (NO MORE USED IN JNI)
268 public static int newWindow() {
269 Window window = ScilabWindow.createWindow();
270 return UIElementMapper.add(window);
274 * Create a new Menubar in Scilab GUIs
275 * @return the ID of the Menubar in the UIElementMapper
277 // TODO REMOVE ME (NO MORE USED IN JNI)
278 public static int newMenuBar() {
279 MenuBar menuBar = ScilabMenuBar.createMenuBar();
280 return UIElementMapper.add(menuBar);
284 * Create a new Menu in Scilab GUIs
285 * @return the ID of the menu in the UIElementMapper
287 // TODO REMOVE ME (NO MORE USED IN JNI)
288 public static int newMenu() {
289 MenuItem menuItem = ScilabMenuItem.createMenuItem(false);
290 return UIElementMapper.add(menuItem);
294 * Create a new ContextMenu in Scilab GUIs
295 * @return the ID of the ContextMenu in the UIElementMapper
297 // TODO REMOVE ME (NO MORE USED IN JNI)
298 public static int newContextMenu() {
299 ContextMenu contextMenu = ScilabContextMenu.createContextMenu();
300 return UIElementMapper.add(contextMenu);
304 * Create a new Color Chooser in Scilab GUIs
305 * @return the ID of the Color Chooser in the UIElementMapper
307 public static int newColorChooser() {
308 ColorChooser colorChooser = ScilabColorChooser.createColorChooser();
309 return UIElementMapper.add(colorChooser);
313 * Create a new Font Chooser in Scilab GUIs
314 * @return the ID of the Font Chooser in the UIElementMapper
316 public static int newFontChooser() {
317 FontChooser fontChooser = ScilabFontChooser.createFontChooser();
318 return UIElementMapper.add(fontChooser);
322 * Create a new MessageBox in Scilab GUIs
323 * @return the ID of the MessageBox in the UIElementMapper
325 // TODO REMOVE ME (NO MORE USED IN JNI)
326 public static int newMessageBox() {
327 MessageBox messageBox = ScilabMessageBox.createMessageBox();
328 return UIElementMapper.add(messageBox);
332 * Create a new PushButton in Scilab GUIs
333 * @return the ID of the PushButton in the UIElementMapper
335 // TODO REMOVE ME (NO MORE USED IN JNI)
336 public static int newPushButton() {
337 PushButton pushButton = ScilabPushButton.createPushButton();
338 int id = UIElementMapper.add(pushButton);
341 setWidgetFontName(id, DEFAULTFONTNAME);
342 setWidgetFontWeight(id, NORMALFONT);
343 setWidgetFontSize(id, DEFAULTFONTSIZE);
345 setWidgetRelief(id, ScilabRelief.RAISED);
348 setWidgetBackgroundColor(id, (int) BUTTON_RED_BACKGROUND, (int) BUTTON_GREEN_BACKGROUND, (int) BUTTON_BLUE_BACKGROUND);
349 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
353 // TODO REMOVE ME (NO MORE USED IN JNI)
354 public static void newPushButton(String UID) {
355 PushButton pushButton = ScilabPushButton.createPushButton();
356 ((ScilabPushButton) pushButton).setIdentifier(UID);
357 int id = UIElementMapper.add(pushButton);
360 setWidgetFontName(id, DEFAULTFONTNAME);
361 setWidgetFontWeight(id, NORMALFONT);
362 setWidgetFontSize(id, DEFAULTFONTSIZE);
364 setWidgetRelief(id, ScilabRelief.RAISED);
367 setWidgetBackgroundColor(id, (int) BUTTON_RED_BACKGROUND, (int) BUTTON_GREEN_BACKGROUND, (int) BUTTON_BLUE_BACKGROUND);
368 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
371 * Create a new EditBox in Scilab GUIs
372 * @return the ID of the Edit in the UIElementMapper
374 // TODO REMOVE ME (NO MORE USED IN JNI)
375 public static int newEditBox() {
376 EditBox editBox = ScilabEditBox.createEditBox();
377 int id = UIElementMapper.add(editBox);
380 setWidgetFontName(id, DEFAULTFONTNAME);
381 setWidgetFontWeight(id, NORMALFONT);
382 setWidgetFontSize(id, DEFAULTFONTSIZE);
384 setWidgetRelief(id, ScilabRelief.SUNKEN);
387 setWidgetBackgroundColor(id, (int) DEFAULT_RED_BACKGROUND, (int) DEFAULT_GREEN_BACKGROUND, (int) DEFAULT_BLUE_BACKGROUND);
388 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
393 * Create a new Label in Scilab GUIs
394 * @return the ID of the Label in the UIElementMapper
396 // TODO REMOVE ME (NO MORE USED IN JNI)
397 public static int newLabel() {
398 Label label = ScilabLabel.createLabel();
399 int id = UIElementMapper.add(label);
402 setWidgetFontName(id, DEFAULTFONTNAME);
403 setWidgetFontWeight(id, NORMALFONT);
404 setWidgetFontSize(id, DEFAULTFONTSIZE);
406 setWidgetRelief(id, ScilabRelief.FLAT);
409 setWidgetBackgroundColor(id, (int) DEFAULT_RED_BACKGROUND, (int) DEFAULT_GREEN_BACKGROUND, (int) DEFAULT_BLUE_BACKGROUND);
410 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
415 * Create a new CheckBox in Scilab GUIs
416 * @return the ID of the CheckBox in the UIElementMapper
418 // TODO REMOVE ME (NO MORE USED IN JNI)
419 public static int newCheckBox() {
420 CheckBox checkBox = ScilabCheckBox.createCheckBox();
421 int id = UIElementMapper.add(checkBox);
424 setWidgetFontName(id, DEFAULTFONTNAME);
425 setWidgetFontWeight(id, NORMALFONT);
426 setWidgetFontSize(id, DEFAULTFONTSIZE);
428 setWidgetRelief(id, ScilabRelief.FLAT);
431 setWidgetBackgroundColor(id, (int) DEFAULT_RED_BACKGROUND, (int) DEFAULT_GREEN_BACKGROUND, (int) DEFAULT_BLUE_BACKGROUND);
432 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
437 * Create a new RadioButton in Scilab GUIs
438 * @return the ID of the RadioButton in the UIElementMapper
440 // TODO REMOVE ME (NO MORE USED IN JNI)
441 public static int newRadioButton() {
442 RadioButton radioButton = ScilabRadioButton.createRadioButton();
443 int id = UIElementMapper.add(radioButton);
446 setWidgetFontName(id, DEFAULTFONTNAME);
447 setWidgetFontWeight(id, NORMALFONT);
448 setWidgetFontSize(id, DEFAULTFONTSIZE);
450 setWidgetRelief(id, ScilabRelief.FLAT);
453 setWidgetBackgroundColor(id, (int) DEFAULT_RED_BACKGROUND, (int) DEFAULT_GREEN_BACKGROUND, (int) DEFAULT_BLUE_BACKGROUND);
454 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
459 * Create a new UiTable in Scilab GUIs
460 * @return the ID of the UiTable in the UIElementMapper
462 // TODO REMOVE ME (NO MORE USED IN JNI)
463 public static int newUiTable() {
464 UiTable uiTable = ScilabUiTable.createUiTable();
465 int id = UIElementMapper.add(uiTable);
468 setWidgetFontName(id, DEFAULTFONTNAME);
469 setWidgetFontWeight(id, NORMALFONT);
470 setWidgetFontSize(id, DEFAULTFONTSIZE);
472 setWidgetRelief(id, ScilabRelief.FLAT);
475 setWidgetBackgroundColor(id, (int) DEFAULT_RED_BACKGROUND, (int) DEFAULT_GREEN_BACKGROUND, (int) DEFAULT_BLUE_BACKGROUND);
476 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
481 * Create a new UiDisplayTree in Scilab GUIs
482 * @return the ID of the UiDisplayTree in the UIElementMapper
484 // TODO REMOVE ME (NO MORE USED IN JNI)
485 public static int newUiDisplayTree() {
486 UiDisplayTree uiTree = ScilabUiDisplayTree.createUiDisplayTree();
487 int id = UIElementMapper.add(uiTree);
490 setWidgetFontName(id, DEFAULTFONTNAME);
491 setWidgetFontWeight(id, NORMALFONT);
492 setWidgetFontSize(id, DEFAULTFONTSIZE);
494 setWidgetRelief(id, ScilabRelief.FLAT);
497 setWidgetBackgroundColor(id, (int) DEFAULT_RED_BACKGROUND, (int) DEFAULT_GREEN_BACKGROUND, (int) DEFAULT_BLUE_BACKGROUND);
498 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
503 * Create a new Slider in Scilab GUIs
504 * @return the ID of the Slider in the UIElementMapper
506 // TODO REMOVE ME (NO MORE USED IN JNI)
507 public static int newSlider() {
508 Slider slider = ScilabSlider.createSlider();
509 int id = UIElementMapper.add(slider);
512 /* Set a default font because is null when JScrollBar is created */
513 slider.setFont(new Font(DEFAULTFONTNAME, Font.PLAIN, DEFAULTFONTSIZE));
514 setWidgetFontName(id, DEFAULTFONTNAME);
515 setWidgetFontWeight(id, NORMALFONT);
516 setWidgetFontSize(id, DEFAULTFONTSIZE);
518 setWidgetRelief(id, ScilabRelief.FLAT);
521 setWidgetBackgroundColor(id, (int) DEFAULT_RED_BACKGROUND, (int) DEFAULT_GREEN_BACKGROUND, (int) DEFAULT_BLUE_BACKGROUND);
522 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
524 slider.setText(""); /* Because Name property is null at creation */
525 slider.setMinimumValue(0);
526 slider.setMaximumValue(1);
527 slider.setUserValue(0);
533 * Create a new ListBox in Scilab GUIs
534 * @return the ID of the ListBox in the UIElementMapper
536 // TODO REMOVE ME (NO MORE USED IN JNI)
537 public static int newListBox() {
538 ListBox listBox = ScilabListBox.createListBox();
539 int id = UIElementMapper.add(listBox);
542 setWidgetFontName(id, DEFAULTFONTNAME);
543 setWidgetFontWeight(id, NORMALFONT);
544 setWidgetFontSize(id, DEFAULTFONTSIZE);
546 setWidgetRelief(id, ScilabRelief.FLAT);
549 setWidgetBackgroundColor(id, (int) DEFAULT_RED_BACKGROUND, (int) DEFAULT_GREEN_BACKGROUND, (int) DEFAULT_BLUE_BACKGROUND);
550 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
555 * Create a new PopupMenu in Scilab GUIs
556 * @return the ID of the PopupMenu in the UIElementMapper
558 // TODO REMOVE ME (NO MORE USED IN JNI)
559 public static int newPopupMenu() {
560 PopupMenu popupMenu = ScilabPopupMenu.createPopupMenu();
561 int id = UIElementMapper.add(popupMenu);
564 setWidgetFontName(id, DEFAULTFONTNAME);
565 setWidgetFontWeight(id, NORMALFONT);
566 setWidgetFontSize(id, DEFAULTFONTSIZE);
568 setWidgetRelief(id, ScilabRelief.FLAT);
571 setWidgetBackgroundColor(id, (int) DEFAULT_RED_BACKGROUND, (int) DEFAULT_GREEN_BACKGROUND, (int) DEFAULT_BLUE_BACKGROUND);
572 setWidgetForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
577 * Create a new Frame in Scilab GUIs
578 * @return the ID of the Frame in the UIElementMapper
580 public static int newFrame() {
581 Frame frame = ScilabFrame.createFrame();
582 int id = UIElementMapper.add(frame);
585 setFrameFontName(id, DEFAULTFONTNAME);
586 setFrameFontWeight(id, NORMALFONT);
587 setFrameFontSize(id, DEFAULTFONTSIZE);
589 setFrameRelief(id, ScilabRelief.RIDGE);
592 setFrameBackgroundColor(id, (int) DEFAULT_RED_BACKGROUND, (int) DEFAULT_GREEN_BACKGROUND, (int) DEFAULT_BLUE_BACKGROUND);
593 setFrameForegroundColor(id, (int) DEFAULT_RED_FOREGROUND, (int) DEFAULT_GREEN_FOREGROUND, (int) DEFAULT_BLUE_FOREGROUND);
595 frame.setText(""); /* Because Name property is null at creation */
600 * Create a new ContextMenu in Scilab GUIs
601 * and wait for a user answer
602 * @param uicontextmenuUID the id of the Context Menu
603 * @return the item of the menu selected
605 public static String displayAndWaitContextMenu(String uicontextmenuUID) {
606 SwingViewObject uicontextmenu = SwingView.getFromId(uicontextmenuUID);
607 return ((SwingScilabContextMenu) uicontextmenu).displayAndWait();
612 * @param id the id of the Widget to destroy
614 // TODO REMOVE ME (NO MORE USED IN JNI)
615 public static void destroyWidget(int id) {
616 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).destroy();
617 UIElementMapper.removeMapping(id);
622 * @param id the id of the Frame to destroy
624 // TODO REMOVE ME (NO MORE USED IN JNI)
625 public static void destroyFrame(int id) {
626 ((Frame) UIElementMapper.getCorrespondingUIElement(id)).destroy();
627 UIElementMapper.removeMapping(id);
631 * Create a new window with id figureIndex.
632 * The created window contains an empty tab.
633 * @param figureIndex index of the figure to create
634 * @return id of the window
636 // TODO REMOVE ME (NO MORE USED IN JNI)
637 public static int newWindow(int figureIndex) {
638 Window newWindow = ScilabWindow.createWindow();
640 newWindow.setTitle(FIGURE_TITLE + figureIndex);
642 MenuBar menuBar = null; //MenuBarBuilder.buildMenuBar(MENUBARXMLFILE, figureIndex);
644 ToolBar toolBar = null; //ToolBarBuilder.buildToolBar(TOOLBARXMLFILE, figureIndex);
646 TextBox infoBar = ScilabTextBox.createTextBox();
648 // create a tab able to display a figure handle
649 Tab graphicTab = ScilabTab.createTab(FIGURE_TITLE + figureIndex, figureIndex);
650 /* Destroy the graphic figure when the tab is closed */
651 // // check if figure is already closed
652 // if (get_figure_handle(fid) <> []) then
653 // if (get(get_figure_handle(fid), 'event_handler_enable') == 'on') then
654 // // execute closing call back
655 // execstr(get(get_figure_handle(fid), 'event_handler') + '(fid, -1, -1, -1000)', 'errcatch', 'm');
657 // // destroy the figure
658 // delete(get_figure_handle(fid));
660 String closingCommand =
661 "if (get_figure_handle(" + figureIndex + ") <> []) then"
662 + " if (get(get_figure_handle(" + figureIndex + "), 'event_handler_enable') == 'on') then"
663 + " execstr(get(get_figure_handle(" + figureIndex + "), 'event_handler')+'(" + figureIndex + ", -1, -1, -1000)', 'errcatch', 'm');"
665 + " delete(get_figure_handle(" + figureIndex + "));"
667 //graphicTab.setCallback(ScilabCloseCallBack.create(figureIndex, closingCommand));
668 graphicTab.addMenuBar(menuBar);
669 graphicTab.addToolBar(toolBar);
670 graphicTab.addInfoBar(infoBar);
671 ((SwingScilabTab) graphicTab.getAsSimpleTab()).setWindowIcon("graphic-window");
672 newWindow.addTab(graphicTab);
674 // link the tab and canvas with their figure
675 // DrawableFigureGL associatedFigure = FigureMapper.getCorrespondingFigure(figureIndex);
676 //associatedFigure.setRendererProperties(new ScilabRendererProperties(graphicTab, graphicCanvas));
677 // associatedFigure.setRendererProperties(new ScilabRendererProperties(graphicTab, null, figureIndex));
678 // don't draw now, figure will show itself when all its parameters will be set
683 /****************************/
685 /* OBJECT DIMENSIONS BRIDGE */
687 /****************************/
690 * Set the dimensions of an object in Scilab GUIs
691 * @param objID the ID of the object in the UIElementMapper
692 * @param width the width of the object
693 * @param height the height of the object
695 public static void setDims(int objID, int width, int height) {
696 UIElementMapper.getCorrespondingUIElement(objID).setDims(new Size(width, height));
699 /**********************/
701 /* OBJECT TEXT BRIDGE */
703 /**********************/
706 * Set the text of a widget in Scilab GUIs
707 * @param objID the ID of the Widget in the UIElementMapper
708 * @param text the text to set to the widget
710 // TODO REMOVE ME (NO MORE USED IN JNI)
711 public static void setWidgetText(int objID, String text) {
712 ((Widget) UIElementMapper.getCorrespondingUIElement(objID)).setText(text);
716 * Get the text of a widget in Scilab GUIs
717 * @param objID the ID of the Widget in the UIElementMapper
718 * @return the text of the widget
720 // TODO REMOVE ME (NO MORE USED IN JNI)
721 public static String getWidgetText(int objID) {
722 return ((Widget) UIElementMapper.getCorrespondingUIElement(objID)).getText();
726 * Set the text of a Frame in Scilab GUIs
727 * @param objID the ID of the Widget in the UIElementMapper
728 * @param text the text to set to the Frame
730 // TODO REMOVE ME (NO MORE USED IN JNI)
731 public static void setFrameText(int objID, String text) {
732 ((Frame) UIElementMapper.getCorrespondingUIElement(objID)).setText(text);
736 * Get the text of a Frame in Scilab GUIs
737 * @param objID the ID of the Frame in the UIElementMapper
738 * @return the text of the Frame
740 // TODO REMOVE ME (NO MORE USED IN JNI)
741 public static String getFrameText(int objID) {
742 return ((Frame) UIElementMapper.getCorrespondingUIElement(objID)).getText();
752 * Set a figure as parent for an UIElement
753 * @param figureID the ID of the figure in the FigureMapper
754 * @param objID the ID of the object in the UIElementMapper
756 // TODO REMOVE ME (NO MORE USED IN JNI)
757 public static void setFigureAsParent(int figureID, int objID) {
758 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
760 if (!(UIElementMapper.getCorrespondingUIElement(objID) instanceof MenuItem)) {
761 // Add the menu to the tab
762 parentTab.getMenuBar().add((Menu) UIElementMapper.getCorrespondingUIElement(objID));
764 // obj is a MenuItem that has to be converted to a Menu
765 MenuItem menuItem = (MenuItem) UIElementMapper.getCorrespondingUIElement(objID);
767 Menu menuToAdd = ScilabMenu.createMenu();
768 UIElementMapper.removeMapping(objID);
769 UIElementMapper.addMapping(objID, menuToAdd);
771 // Copy all properties from MenuItem to Menu
772 menuToAdd.setText(menuItem.getText());
773 menuToAdd.setCallback(menuItem.getCallback());
774 menuToAdd.setForeground(menuItem.getForeground());
775 menuToAdd.setVisible(menuItem.isVisible());
776 menuToAdd.setEnabled(menuItem.isEnabled());
777 menuToAdd.setChecked(menuItem.isChecked());
778 // End of properties copy
780 // Add the menu to the tab
781 parentTab.getMenuBar().add(menuToAdd);
786 * Set a figure as parent for a PushButton
787 * @param figureID the ID of the figure in the FigureMapper
788 * @param objID the ID of the PushButton in the UIElementMapper
790 // TODO REMOVE ME (NO MORE USED IN JNI)
791 public static void setPushButtonParent(int figureID, int objID) {
792 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
793 PushButton pushButton = (PushButton) UIElementMapper.getCorrespondingUIElement(objID);
794 ScilabBridge.addMember(parentTab, pushButton);*/
798 * Remove a PushButton from its parent figure
799 * @param figureID the ID of the figure in the FigureMapper
800 * @param objID the ID of the PushButton in the UIElementMapper
802 // TODO REMOVE ME (NO MORE USED IN JNI)
803 public static void removePushButtonFromParent(int figureID, int objID) {
804 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
805 PushButton pushButton = (PushButton) UIElementMapper.getCorrespondingUIElement(objID);
806 ScilabBridge.removeMember(parentTab, pushButton);*/
810 * Set a figure as parent for a EditBox
811 * @param figureID the ID of the figure in the FigureMapper
812 * @param objID the ID of the PushButton in the UIElementMapper
814 // TODO REMOVE ME (NO MORE USED IN JNI)
815 public static void setEditBoxParent(int figureID, int objID) {
816 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
817 EditBox editBox = (EditBox) UIElementMapper.getCorrespondingUIElement(objID);
818 ScilabBridge.addMember(parentTab, editBox);*/
822 * Remove an EditBox from its parent figure
823 * @param figureID the ID of the figure in the FigureMapper
824 * @param objID the ID of the PushButton in the UIElementMapper
826 // TODO REMOVE ME (NO MORE USED IN JNI)
827 public static void removeEditBoxFromParent(int figureID, int objID) {
828 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
829 EditBox editBox = (EditBox) UIElementMapper.getCorrespondingUIElement(objID);
830 ScilabBridge.removeMember(parentTab, editBox);*/
834 * Set a figure as parent for a Label
835 * @param figureID the ID of the figure in the FigureMapper
836 * @param objID the ID of the PushButton in the UIElementMapper
838 // TODO REMOVE ME (NO MORE USED IN JNI)
839 public static void setLabelParent(int figureID, int objID) {
840 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
841 Label label = (Label) UIElementMapper.getCorrespondingUIElement(objID);
842 ScilabBridge.addMember(parentTab, label);*/
846 * Remove a Label from its parent figure
847 * @param figureID the ID of the figure in the FigureMapper
848 * @param objID the ID of the PushButton in the UIElementMapper
850 // TODO REMOVE ME (NO MORE USED IN JNI)
851 public static void removeLabelFromParent(int figureID, int objID) {
852 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
853 Label label = (Label) UIElementMapper.getCorrespondingUIElement(objID);
854 ScilabBridge.removeMember(parentTab, label);*/
858 * Set a figure as parent for a CheckBox
859 * @param figureID the ID of the figure in the FigureMapper
860 * @param objID the ID of the PushButton in the UIElementMapper
862 // TODO REMOVE ME (NO MORE USED IN JNI)
863 public static void setCheckBoxParent(int figureID, int objID) {
864 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
865 CheckBox checkBox = (CheckBox) UIElementMapper.getCorrespondingUIElement(objID);
866 ScilabBridge.addMember(parentTab, checkBox);*/
870 * Remove a CheckBox from its parent figure
871 * @param figureID the ID of the figure in the FigureMapper
872 * @param objID the ID of the PushButton in the UIElementMapper
874 // TODO REMOVE ME (NO MORE USED IN JNI)
875 public static void removeCheckBoxFromParent(int figureID, int objID) {
876 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
877 CheckBox checkBox = (CheckBox) UIElementMapper.getCorrespondingUIElement(objID);
878 ScilabBridge.removeMember(parentTab, checkBox);*/
882 * Set a figure as parent for a RadioButton
883 * @param figureID the ID of the figure in the FigureMapper
884 * @param objID the ID of the PushButton in the UIElementMapper
886 // TODO REMOVE ME (NO MORE USED IN JNI)
887 public static void setRadioButtonParent(int figureID, int objID) {
888 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
889 RadioButton radioButton = (RadioButton) UIElementMapper.getCorrespondingUIElement(objID);
890 ScilabBridge.addMember(parentTab, radioButton);*/
894 * Remove a RadioButton from its parent figure
895 * @param figureID the ID of the figure in the FigureMapper
896 * @param objID the ID of the PushButton in the UIElementMapper
898 // TODO REMOVE ME (NO MORE USED IN JNI)
899 public static void removeRadioButtonFromParent(int figureID, int objID) {
900 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
901 RadioButton radioButton = (RadioButton) UIElementMapper.getCorrespondingUIElement(objID);
902 ScilabBridge.removeMember(parentTab, radioButton);*/
906 * Set a figure as parent for a UiTable
907 * @param figureID the ID of the figure in the FigureMapper
908 * @param objID the ID of the PushButton in the UIElementMapper
910 // TODO REMOVE ME (NO MORE USED IN JNI)
911 public static void setUiTableParent(int figureID, int objID) {
912 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
913 UiTable uiTable = (UiTable) UIElementMapper.getCorrespondingUIElement(objID);
914 ScilabBridge.addMember(parentTab, uiTable);*/
918 * Remove a UiTable from its parent figure
919 * @param figureID the ID of the figure in the FigureMapper
920 * @param objID the ID of the PushButton in the UIElementMapper
922 // TODO REMOVE ME (NO MORE USED IN JNI)
923 public static void removeUiTableFromParent(int figureID, int objID) {
924 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
925 UiTable uiTable = (UiTable) UIElementMapper.getCorrespondingUIElement(objID);
926 ScilabBridge.removeMember(parentTab, uiTable);*/
929 // TODO REMOVE ME (NO MORE USED IN JNI)
930 public static void setUiDisplayTreeParent(int figureID, int objID) {
931 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
932 UiDisplayTree uiTree = (UiDisplayTree) UIElementMapper.getCorrespondingUIElement(objID);
933 ScilabBridge.addMember(parentTab, uiTree);*/
935 // TODO REMOVE ME (NO MORE USED IN JNI)
936 public static void removeUiDisplayTreeFromParent(int figureID, int objID) {
937 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
938 UiDisplayTree uiTree = (UiDisplayTree) UIElementMapper.getCorrespondingUIElement(objID);
939 ScilabBridge.removeMember(parentTab, uiTree);*/
943 * Set a figure as parent for a Slider
944 * @param figureID the ID of the figure in the FigureMapper
945 * @param objID the ID of the PushButton in the UIElementMapper
947 // TODO REMOVE ME (NO MORE USED IN JNI)
948 public static void setSliderParent(int figureID, int objID) {
949 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
950 Slider slider = (Slider) UIElementMapper.getCorrespondingUIElement(objID);
951 ScilabBridge.addMember(parentTab, slider);*/
955 * Remove a Slider from its parent figure
956 * @param figureID the ID of the figure in the FigureMapper
957 * @param objID the ID of the Slider in the UIElementMapper
959 // TODO REMOVE ME (NO MORE USED IN JNI)
960 public static void removeSliderFromParent(int figureID, int objID) {
961 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
962 Slider slider = (Slider) UIElementMapper.getCorrespondingUIElement(objID);
963 ScilabBridge.removeMember(parentTab, slider);*/
967 * Set a figure as parent for a ListBox
968 * @param figureID the ID of the figure in the FigureMapper
969 * @param objID the ID of the ListBox in the UIElementMapper
971 // TODO REMOVE ME (NO MORE USED IN JNI)
972 public static void setListBoxParent(int figureID, int objID) {
973 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
974 ListBox listBox = (ListBox) UIElementMapper.getCorrespondingUIElement(objID);
975 ScilabBridge.addMember(parentTab, listBox);*/
979 * Remove a ListBox from its parent figure
980 * @param figureID the ID of the figure in the FigureMapper
981 * @param objID the ID of the ListBox in the UIElementMapper
983 // TODO REMOVE ME (NO MORE USED IN JNI)
984 public static void removeListBoxFromParent(int figureID, int objID) {
985 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
986 ListBox listBox = (ListBox) UIElementMapper.getCorrespondingUIElement(objID);
987 ScilabBridge.removeMember(parentTab, listBox);*/
991 * Set a figure as parent for a PopupMenu
992 * @param figureID the ID of the figure in the FigureMapper
993 * @param objID the ID of the PopupMenu in the UIElementMapper
995 // TODO REMOVE ME (NO MORE USED IN JNI)
996 public static void setPopupMenuParent(int figureID, int objID) {
997 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
998 PopupMenu popupMenu = (PopupMenu) UIElementMapper.getCorrespondingUIElement(objID);
999 ScilabBridge.addMember(parentTab, popupMenu);*/
1003 * Remove a PopupMenu from its parent figure
1004 * @param figureID the ID of the figure in the FigureMapper
1005 * @param objID the ID of the PopupMenu in the UIElementMapper
1007 // TODO REMOVE ME (NO MORE USED IN JNI)
1008 public static void removePopupMenuFromParent(int figureID, int objID) {
1009 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
1010 PopupMenu popupMenu = (PopupMenu) UIElementMapper.getCorrespondingUIElement(objID);
1011 ScilabBridge.removeMember(parentTab, popupMenu);*/
1015 * Set a figure as parent for a Frame
1016 * @param figureID the ID of the figure in the FigureMapper
1017 * @param objID the ID of the PopupMenu in the UIElementMapper
1019 // TODO REMOVE ME (NO MORE USED IN JNI)
1020 public static void setFrameParent(int figureID, int objID) {
1021 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
1022 Frame frame = (Frame) UIElementMapper.getCorrespondingUIElement(objID);
1023 ScilabBridge.addMember(parentTab, frame);*/
1027 * Remove a Frame from its parent figure
1028 * @param figureID the ID of the figure in the FigureMapper
1029 * @param objID the ID of the PopupMenu in the UIElementMapper
1031 // TODO REMOVE ME (NO MORE USED IN JNI)
1032 public static void removeFrameFromParent(int figureID, int objID) {
1033 /*Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureID).getRendererProperties()).getParentTab();
1034 Frame frame = (Frame) UIElementMapper.getCorrespondingUIElement(objID);
1035 ScilabBridge.removeMember(parentTab, frame);*/
1039 * Set root Scilab object (the console tab) as the parent of the menu
1040 * @param objID the id of the menu
1042 // TODO REMOVE ME (NO MORE USED IN JNI)
1043 public static void setRootAsParent(int objID) {
1044 if (!(UIElementMapper.getCorrespondingUIElement(objID) instanceof MenuItem)) {
1045 // Add the menu to the tab
1046 ScilabConsole.getConsole().getMenuBar().add((Menu) UIElementMapper.getCorrespondingUIElement(objID));
1048 // obj is a MenuItem that has top be converted to a Menu
1049 MenuItem menuItem = (MenuItem) UIElementMapper.getCorrespondingUIElement(objID);
1051 Menu menuToAdd = ScilabMenu.createMenu();
1052 UIElementMapper.removeMapping(objID);
1053 UIElementMapper.addMapping(objID, menuToAdd);
1054 // Copy all properties from MenuItem to Menu
1055 menuToAdd.setText(menuItem.getText());
1056 menuToAdd.setCallback(menuItem.getCallback());
1057 menuToAdd.setForeground(menuItem.getForeground());
1058 menuToAdd.setVisible(menuItem.isVisible());
1059 // End of properties copy
1061 ScilabConsole.getConsole().getMenuBar().add(menuToAdd);
1066 * Set an other menu as the parent of the menu
1067 * @param menuID the id of the parent menu
1068 * @param objID the id of the menu
1070 // TODO REMOVE ME (NO MORE USED IN JNI)
1071 public static void setMenuAsParent(int menuID, int objID) {
1073 if (UIElementMapper.getCorrespondingUIElement(menuID) instanceof CheckBoxMenuItem) {
1074 CheckBoxMenuItem parentMenu = (CheckBoxMenuItem) UIElementMapper.getCorrespondingUIElement(menuID);
1076 if (!(UIElementMapper.getCorrespondingUIElement(objID) instanceof MenuItem)) {
1077 parentMenu.add((Menu) UIElementMapper.getCorrespondingUIElement(objID));
1078 } else if (UIElementMapper.getCorrespondingUIElement(objID) instanceof MenuItem) {
1079 parentMenu.add((MenuItem) UIElementMapper.getCorrespondingUIElement(objID));
1081 } else if (UIElementMapper.getCorrespondingUIElement(menuID) instanceof MenuItem) {
1082 MenuItem parentMenu = (MenuItem) UIElementMapper.getCorrespondingUIElement(menuID);
1084 if (!(UIElementMapper.getCorrespondingUIElement(objID) instanceof MenuItem)) {
1085 parentMenu.add((Menu) UIElementMapper.getCorrespondingUIElement(objID));
1086 } else if (UIElementMapper.getCorrespondingUIElement(objID) instanceof MenuItem) {
1087 parentMenu.add((MenuItem) UIElementMapper.getCorrespondingUIElement(objID));
1089 } else if (UIElementMapper.getCorrespondingUIElement(menuID) instanceof ContextMenu) {
1090 ContextMenu parentMenu = (ContextMenu) UIElementMapper.getCorrespondingUIElement(menuID);
1092 if (!(UIElementMapper.getCorrespondingUIElement(objID) instanceof MenuItem)) {
1093 parentMenu.add((Menu) UIElementMapper.getCorrespondingUIElement(objID));
1094 } else if (UIElementMapper.getCorrespondingUIElement(objID) instanceof MenuItem) {
1095 parentMenu.add((MenuItem) UIElementMapper.getCorrespondingUIElement(objID));
1097 } else if (UIElementMapper.getCorrespondingUIElement(menuID) instanceof Menu) {
1098 Menu parentMenu = (Menu) UIElementMapper.getCorrespondingUIElement(menuID);
1100 if (!(UIElementMapper.getCorrespondingUIElement(objID) instanceof MenuItem)) {
1101 parentMenu.add((Menu) UIElementMapper.getCorrespondingUIElement(objID));
1102 } else if (UIElementMapper.getCorrespondingUIElement(objID) instanceof MenuItem) {
1103 parentMenu.add((MenuItem) UIElementMapper.getCorrespondingUIElement(objID));
1108 /*******************/
1110 /* OBJECT CALLBACK */
1112 /*******************/
1115 * Set a callback for a Widget
1116 * @param objID the ID of the object in the UIElementMapper
1117 * @param callbackString the text of the callback
1118 * @param callbackType the type of the callback
1120 // TODO REMOVE ME (NO MORE USED IN JNI)
1121 public static void setWidgetCallback(int objID, String callbackString, int callbackType) {
1122 //((Widget) UIElementMapper.getCorrespondingUIElement(objID))
1123 //.setCallback(CommonCallBack.createCallback(callbackString, callbackType, objID));
1127 * Set a callback for a Frame
1128 * @param objID the ID of the object in the UIElementMapper
1129 * @param callbackString the text of the callback
1130 * @param callbackType the type of the callback
1132 // TODO REMOVE ME (NO MORE USED IN JNI)
1133 public static void setFrameCallback(int objID, String callbackString, int callbackType) {
1134 //((Frame) UIElementMapper.getCorrespondingUIElement(objID)).setCallback(CommonCallBack.createCallback(callbackString, callbackType, objID));
1137 /************************/
1139 /* ENABLE/DISABLE MENUS */
1141 /************************/
1144 * Enable/Disable a menu of a Scilab figure or console giving its name
1145 * @param parentUID the UID of the figure or console
1146 * @param menuName the name of the menu
1147 * @param status true to set the menu enabled
1149 public static void setMenuEnabled(String parentUID, String menuName, boolean status) {
1150 SwingScilabTab parentTab = (SwingScilabTab) SwingView.getFromId(parentUID);
1151 if (parentTab != null) { /** Parent must exist */
1152 parentTab.getMenuBar().getAsSimpleMenuBar().setMenuEnabled(menuName, status);
1157 * Disable a MenuItem of a Scilab figure or console giving its parent name and position
1158 * @param parentUID the UID of the figure or console
1159 * @param parentMenuName the name of the parent menu
1160 * @param menuItemPosition the name of the parent menu
1161 * @param status true to set the menu enabled
1163 public static void setSubMenuEnabled(String parentUID, String parentMenuName, int menuItemPosition, boolean status) {
1164 SwingScilabTab parentTab = (SwingScilabTab) SwingView.getFromId(parentUID);
1165 if (parentTab != null) { /** Parent must exist */
1166 parentTab.getMenuBar().getAsSimpleMenuBar().setSubMenuEnabled(parentMenuName, menuItemPosition, status);
1177 * Delete a menu of a Scilab figure or console giving its name
1178 * @param parentUID the UID of the figure or console
1179 * @param menuName the name of the menu
1181 public static void removeMenu(String parentUID, String menuName) {
1182 SwingScilabTab parentTab = (SwingScilabTab) SwingView.getFromId(parentUID);
1183 if (parentTab != null) { /** Parent must exist */
1184 parentTab.getMenuBar().getAsSimpleMenuBar().removeMenu(menuName);
1188 /***********************/
1190 /* FILE CHOOSER BRIDGE */
1192 /***********************/
1197 * Create a new Graphic Export File Chooser in Scilab GUIs
1198 * @param figureId id of the figure to export
1199 * @return the ID of the File Chooser in the UIElementMapper
1202 public static int newExportFileChooser(String figureId) {
1203 FileChooser fileChooser = ScilabFileChooser.createExportFileChooser(figureId);
1209 /**********************/
1211 /* MESSAGE BOX BRIDGE */
1213 /**********************/
1216 * Set the MessageBox title
1217 * @param id the id of the messageBox
1218 * @param title the title of the messageBox
1220 public static void setMessageBoxTitle(int id, String title) {
1221 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setTitle(title);
1225 * Set the MessageBox message
1226 * @param id the id of the messageBox
1227 * @param message the message of the messageBox
1229 public static void setMessageBoxMessage(int id, String message) {
1230 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setMessage(message);
1234 * Set the MessageBox message (multi-line)
1235 * @param id the id of the messageBox
1236 * @param message the message of the messageBox
1238 public static void setMessageBoxMessage(int id, String[] message) {
1239 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setMessage(message);
1243 * Display this chooser and wait for user selection
1244 * @param id the id of the messageBox
1246 public static void messageBoxDisplayAndWait(int id) {
1247 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).displayAndWait();
1251 * Get the index of the selected button
1252 * @param id the id of the messageBox
1253 * @return the index of the selected button
1255 public static int getMessageBoxSelectedButton(int id) {
1256 return ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).getSelectedButton();
1260 * Set the indices of the default selected buttons (x_choices)
1261 * @param id the id of the MessageBox
1262 * @param indices the indices of the default selected buttons
1264 public static void setMessageBoxDefaultSelectedButtons(int id, int[] indices) {
1265 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setDefaultSelectedButtons(indices);
1269 * Get the indices of the user selected buttons (x_choices)
1270 * @param id the id of the MessageBox
1271 * @return the indices of the user selected buttons
1273 public static int[] getMessageBoxUserSelectedButtons(int id) {
1274 return ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).getUserSelectedButtons();
1278 * Set the labels of the buttons in the MessageBox
1279 * @param id the id of the MessageBox
1280 * @param labels the labels of the buttons
1282 public static void setMessageBoxButtonsLabels(int id, String[] labels) {
1283 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setButtonsLabels(labels);
1287 * Set the initial value for the editable part of the MessageBox
1288 * @param id the id of the MessageBox
1289 * @param value the initial value
1291 public static void setMessageBoxInitialValue(int id, String[] value) {
1292 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setInitialValue(value);
1296 * Get the value of the editable zone in the MessageBox
1297 * @param id the id of the MessageBox
1300 public static String[] getMessageBoxValue(int id) {
1301 return ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).getValue();
1305 * Get the size of the value of the editable zone in the MessageBox
1306 * @param id the id of the MessageBox
1307 * @return the value size
1309 public static int getMessageBoxValueSize(int id) {
1310 return ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).getValueSize();
1314 * Set the items of the listbox in the MessageBox
1315 * @param id the id of the MessageBox
1316 * @param items the items to set
1318 public static void setMessageBoxListBoxItems(int id, String[] items) {
1319 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setListBoxItems(items);
1323 * Get the index of the selected item in the listbox in the MessageBox
1324 * @param id the id of the MessageBox
1327 public static int getMessageBoxSelectedItem(int id) {
1328 return ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).getSelectedItem();
1332 * Set the name of the lines labels in the editable zone in the MessageBox
1333 * @param id the id of the MessageBox
1334 * @param labels the labels
1336 public static void setMessageBoxLineLabels(int id, String[] labels) {
1337 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setLineLabels(labels);
1341 * Set the name of the columns labels in the editable zone in the MessageBox
1342 * @param id the id of the MessageBox
1343 * @param labels the labels
1345 public static void setMessageBoxColumnLabels(int id, String[] labels) {
1346 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setColumnLabels(labels);
1350 * Set the default values of a multi-value editable zone in the MessageBox
1351 * @param id the id of the MessageBox
1352 * @param values the values
1354 public static void setMessageBoxDefaultInput(int id, String[] values) {
1355 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setDefaultInput(values);
1359 * Set a MessageBox modal or not
1360 * @param id the id of the MessageBox
1361 * @param status true to set the MessageBox modal and false else
1363 public static void setMessageBoxModal(int id, boolean status) {
1364 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setModal(status);
1368 * Set the MessageBox icon
1369 * @param id the id of the MessageBox
1370 * @param name the name of the icon
1372 public static void setMessageBoxIcon(int id, String name) {
1373 ((MessageBox) UIElementMapper.getCorrespondingUIElement(id)).setIcon(name);
1376 /************************/
1378 /* OBJECT COLORS BRIDGE */
1380 /************************/
1383 * Builds a color with composants between 0 and 255
1384 * @param red the red value for the color
1385 * @param green the green value for the color
1386 * @param blue the blue value for the color
1388 public static Color getGoodColor(int red, int green, int blue) {
1389 int r = Math.max(0, Math.min(red, 255));
1390 int g = Math.max(0, Math.min(green, 255));
1391 int b = Math.max(0, Math.min(blue, 255));
1393 return new Color(r, g, b);
1397 * Set the background color of a Widget
1398 * @param id the id of the Widget
1399 * @param red the red value for the color
1400 * @param green the green value for the color
1401 * @param blue the blue value for the color
1403 // TODO REMOVE ME (NO MORE USED IN JNI)
1404 public static void setWidgetBackgroundColor(int id, int red, int green, int blue) {
1405 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setBackground(getGoodColor(red, green, blue));
1409 * Get the background color of a widget
1410 * @param id the id of the widget
1411 * @return the color [R, G, B]
1413 // TODO REMOVE ME (NO MORE USED IN JNI)
1414 public static int[] getWidgetBackgroundColor(int id) {
1415 Color tmpColor = ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getBackground();
1416 int[] color = new int[NB_COLORS];
1417 color[0] = tmpColor.getRed();
1418 color[1] = tmpColor.getGreen();
1419 color[2] = tmpColor.getBlue();
1424 * Set the foreground color of a Widget
1425 * @param id the id of the Widget
1426 * @param red the red value for the color
1427 * @param green the green value for the color
1428 * @param blue the blue value for the color
1430 // TODO REMOVE ME (NO MORE USED IN JNI)
1431 public static void setWidgetForegroundColor(int id, int red, int green, int blue) {
1432 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setForeground(getGoodColor(red, green, blue));
1436 * Get the foreground color of a Widget
1437 * @param id the id of the Widget
1438 * @return the color [R, G, B]
1440 // TODO REMOVE ME (NO MORE USED IN JNI)
1441 public static int[] getWidgetForegroundColor(int id) {
1442 Color tmpColor = ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getForeground();
1443 int[] color = new int[NB_COLORS];
1444 color[0] = tmpColor.getRed();
1445 color[1] = tmpColor.getGreen();
1446 color[2] = tmpColor.getBlue();
1451 * Set the background color of a Frame
1452 * @param id the id of the Frame
1453 * @param red the red value for the color
1454 * @param green the green value for the color
1455 * @param blue the blue value for the color
1457 // TODO REMOVE ME (NO MORE USED IN JNI)
1458 public static void setFrameBackgroundColor(int id, int red, int green, int blue) {
1459 ((Frame) UIElementMapper.getCorrespondingUIElement(id)).setBackground(getGoodColor(red, green, blue));
1463 * Get the background color of a Frame
1464 * @param id the id of the Frame
1465 * @return the color [R, G, B]
1467 // TODO REMOVE ME (NO MORE USED IN JNI)
1468 public static int[] getFrameBackgroundColor(int id) {
1469 Color tmpColor = ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getBackground();
1470 int[] color = new int[NB_COLORS];
1471 color[0] = tmpColor.getRed();
1472 color[1] = tmpColor.getGreen();
1473 color[2] = tmpColor.getBlue();
1478 * Set the foreground color of a Frame
1479 * @param id the id of the Frame
1480 * @param red the red value for the color
1481 * @param green the green value for the color
1482 * @param blue the blue value for the color
1484 // TODO REMOVE ME (NO MORE USED IN JNI)
1485 public static void setFrameForegroundColor(int id, int red, int green, int blue) {
1486 ((Frame) UIElementMapper.getCorrespondingUIElement(id)).setForeground(getGoodColor(red, green, blue));
1490 * Get the foreground color of a Frame
1491 * @param id the id of the Frame
1492 * @return the color [R, G, B]
1494 // TODO REMOVE ME (NO MORE USED IN JNI)
1495 public static int[] getFrameForegroundColor(int id) {
1496 Color tmpColor = ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getForeground();
1497 int[] color = new int[NB_COLORS];
1498 color[0] = tmpColor.getRed();
1499 color[1] = tmpColor.getGreen();
1500 color[2] = tmpColor.getBlue();
1504 /**********************/
1506 /* OBJECT FONT BRIDGE */
1508 /**********************/
1511 * Set the name of a Widget font
1512 * @param id the id of the Widget
1513 * @param name the name of the Widget font
1515 // TODO REMOVE ME (NO MORE USED IN JNI)
1516 public static void setWidgetFontName(int id, String name) {
1517 Font font = ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getFont();
1518 font = new Font(name, font.getStyle(), font.getSize());
1519 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setFont(font);
1523 * Get the name of a Widget font
1524 * @param id the id of the Widget
1525 * @return the name of the Widget font
1527 // TODO REMOVE ME (NO MORE USED IN JNI)
1528 public static String getWidgetFontName(int id) {
1529 return ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getFont().getName();
1533 * Set the weight of a Widget font
1534 * @param id the id of the Widget
1535 * @param weight the weight of the Widget font
1537 // TODO REMOVE ME (NO MORE USED IN JNI)
1538 public static void setWidgetFontWeight(int id, String weight) {
1539 Font font = ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getFont();
1541 if (weight.equals(BOLDFONT)) {
1542 if (font.isItalic()) {
1543 font = new Font(font.getName(), Font.ITALIC + Font.BOLD, font.getSize());
1545 font = new Font(font.getName(), Font.BOLD, font.getSize());
1548 if (font.isItalic()) {
1549 font = new Font(font.getName(), Font.ITALIC, font.getSize());
1551 font = new Font(font.getName(), Font.PLAIN, font.getSize());
1555 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setFont(font);
1559 * Set the angle of a Widget font
1560 * @param id the id of the Widget
1561 * @param angle the angle of the Widget font
1563 // TODO REMOVE ME (NO MORE USED IN JNI)
1564 public static void setWidgetFontAngle(int id, String angle) {
1565 Font font = ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getFont();
1567 if (angle.equals(ITALICFONT) || angle.equals(OBLIQUEFONT)) {
1568 if (font.isBold()) {
1569 font = new Font(font.getName(), Font.ITALIC + Font.BOLD, font.getSize());
1571 font = new Font(font.getName(), Font.ITALIC, font.getSize());
1574 if (font.isBold()) {
1575 font = new Font(font.getName(), Font.BOLD, font.getSize());
1577 font = new Font(font.getName(), Font.PLAIN, font.getSize());
1581 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setFont(font);
1585 * Set the size of a Widget font
1586 * @param id the id of the Widget
1587 * @param size the size of the Widget font
1589 // TODO REMOVE ME (NO MORE USED IN JNI)
1590 public static void setWidgetFontSize(int id, int size) {
1591 Font font = ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getFont();
1592 font = new Font(font.getName(), font.getStyle(), size);
1593 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setFont(font);
1597 * Get the size of a Widget font
1598 * @param id the id of the Widget
1599 * @return the size of the Widget font
1601 // TODO REMOVE ME (NO MORE USED IN JNI)
1602 public static int getWidgetFontSize(int id) {
1603 return ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getFont().getSize();
1607 * Set the weight of a Frame font
1608 * @param id the id of the Frame
1609 * @param weight the weight of the Frame font
1611 // TODO REMOVE ME (NO MORE USED IN JNI)
1612 public static void setFrameFontWeight(int id, String weight) {
1613 Font font = ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getFont();
1615 if (weight.equals(BOLDFONT)) {
1616 if (font.isItalic()) {
1617 font = new Font(font.getName(), Font.ITALIC + Font.BOLD, font.getSize());
1619 font = new Font(font.getName(), Font.BOLD, font.getSize());
1622 if (font.isItalic()) {
1623 font = new Font(font.getName(), Font.ITALIC, font.getSize());
1625 font = new Font(font.getName(), Font.PLAIN, font.getSize());
1629 ((Frame) UIElementMapper.getCorrespondingUIElement(id)).setFont(font);
1633 * Set the angle of a Frame font
1634 * @param id the id of the Frame
1635 * @param angle the angle of the Frame font
1637 // TODO REMOVE ME (NO MORE USED IN JNI)
1638 public static void setFrameFontAngle(int id, String angle) {
1639 Font font = ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getFont();
1641 if (angle.equals(ITALICFONT) || angle.equals(OBLIQUEFONT)) {
1642 if (font.isBold()) {
1643 font = new Font(font.getName(), Font.ITALIC + Font.BOLD, font.getSize());
1645 font = new Font(font.getName(), Font.ITALIC, font.getSize());
1648 if (font.isBold()) {
1649 font = new Font(font.getName(), Font.BOLD, font.getSize());
1651 font = new Font(font.getName(), Font.PLAIN, font.getSize());
1655 ((Frame) UIElementMapper.getCorrespondingUIElement(id)).setFont(font);
1659 * Set the size of a Frame font
1660 * @param id the id of the Frame
1661 * @param size the size of the Frame font
1663 // TODO REMOVE ME (NO MORE USED IN JNI)
1664 public static void setFrameFontSize(int id, int size) {
1665 Font font = ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getFont();
1666 font = new Font(font.getName(), font.getStyle(), size);
1667 ((Frame) UIElementMapper.getCorrespondingUIElement(id)).setFont(font);
1671 * Get the size of a Frame font
1672 * @param id the id of the Frame
1673 * @return the size of the Frame font
1675 // TODO REMOVE ME (NO MORE USED IN JNI)
1676 public static int getFrameFontSize(int id) {
1677 return ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getFont().getSize();
1681 * Set the name of a Frame font
1682 * @param id the id of the Frame
1683 * @param name the name of the Frame font
1685 // TODO REMOVE ME (NO MORE USED IN JNI)
1686 public static void setFrameFontName(int id, String name) {
1687 Font font = ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getFont();
1688 font = new Font(name, font.getStyle(), font.getSize());
1689 ((Frame) UIElementMapper.getCorrespondingUIElement(id)).setFont(font);
1693 * Get the name of a Frame font
1694 * @param id the id of the Frame
1695 * @return the name of the Frame font
1697 // TODO REMOVE ME (NO MORE USED IN JNI)
1698 public static String getFrameFontName(int id) {
1699 return ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getFont().getName();
1702 /**************************/
1704 /* OBJECT POSITION BRIDGE */
1706 /**************************/
1709 * Set the position (in Scilab terms) of a Widget
1710 * @param id the id of the Widget
1711 * @param x the X-coordinate for the Widget
1712 * @param y the Y-coordinate for the Widget
1713 * @param width the width of the Widget
1714 * @param height the height of the Widget
1716 // TODO REMOVE ME (NO MORE USED IN JNI)
1717 public static void setWidgetPosition(int id, int x, int y, int width, int height) {
1718 /* Dimensions must be set before position beacause of PositionConverter */
1719 UIElementMapper.getCorrespondingUIElement(id).setDims(new Size(width, height));
1720 UIElementMapper.getCorrespondingUIElement(id).setPosition(new Position(x, y));
1724 * Get the position (in Scilab terms) of a widget
1725 * @param id the id of the widget
1726 * @return the position (X-coordinate, Y-coordinate, width, height) of the button
1728 // TODO REMOVE ME (NO MORE USED IN JNI)
1729 public static int[] getWidgetPosition(int id) {
1730 int[] position = new int[POSITION_SIZE];
1732 position[X_INDEX] = ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getPosition().getX();
1733 position[Y_INDEX] = ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getPosition().getY();
1734 position[WIDTH_INDEX] = ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getDims().getWidth();
1735 position[HEIGHT_INDEX] = ((Widget) UIElementMapper.getCorrespondingUIElement(id)).getDims().getHeight();
1741 * Set the position (in Scilab terms) of a Frame
1742 * @param id the id of the Frame
1743 * @param x the X-coordinate for the Frame
1744 * @param y the Y-coordinate for the Frame
1745 * @param width the width of the Frame
1746 * @param height the height of the Frame
1748 // TODO REMOVE ME (NO MORE USED IN JNI)
1749 public static void setFramePosition(int id, int x, int y, int width, int height) {
1750 /* Dimensions must be set before position beacause of PositionConverter */
1751 UIElementMapper.getCorrespondingUIElement(id).setDims(new Size(width, height));
1752 UIElementMapper.getCorrespondingUIElement(id).setPosition(new Position(x, y));
1756 * Get the position (in Scilab terms) of a Frame
1757 * @param id the id of the Frame
1758 * @return the position (X-coordinate, Y-coordinate, width, height) of the button
1760 // TODO REMOVE ME (NO MORE USED IN JNI)
1761 public static int[] getFramePosition(int id) {
1762 int[] position = new int[POSITION_SIZE];
1764 position[X_INDEX] = ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getPosition().getX();
1765 position[Y_INDEX] = ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getPosition().getY();
1766 position[WIDTH_INDEX] = ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getDims().getWidth();
1767 position[HEIGHT_INDEX] = ((Frame) UIElementMapper.getCorrespondingUIElement(id)).getDims().getHeight();
1772 /***************************/
1774 /* OBJECT ALIGNMENT BRIDGE */
1776 /***************************/
1779 * Set the horizontal alignment for the Widget text
1780 * @param id the id of the Widget
1781 * @param alignment the value for the alignment (See ScilabAlignment.java)
1783 // TODO REMOVE ME (NO MORE USED IN JNI)
1784 public static void setWidgetHorizontalAlignment(int id, String alignment) {
1785 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setHorizontalAlignment(alignment);
1789 * Set the vertical alignment for the Widget text
1790 * @param id the id of the Widget
1791 * @param alignment the value for the alignment (See ScilabAlignment.java)
1793 // TODO REMOVE ME (NO MORE USED IN JNI)
1794 public static void setWidgetVerticalAlignment(int id, String alignment) {
1795 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setVerticalAlignment(alignment);
1798 /**********************/
1800 /* SLIDER STEP BRIDGE */
1802 /**********************/
1805 * Set the minor tick spacing for a Slider
1806 * @param id the id of the Slider
1807 * @param space the increment value
1809 // TODO REMOVE ME (NO MORE USED IN JNI)
1810 public static void setSliderMinorTickSpacing(int id, int space) {
1811 ((Slider) UIElementMapper.getCorrespondingUIElement(id)).setMinorTickSpacing(space);
1815 * Set the major tick spacing for a Slider
1816 * @param id the id of the Slider
1817 * @param space the increment value
1819 // TODO REMOVE ME (NO MORE USED IN JNI)
1820 public static void setSliderMajorTickSpacing(int id, int space) {
1821 ((Slider) UIElementMapper.getCorrespondingUIElement(id)).setMajorTickSpacing(space);
1824 /*************************/
1826 /* SLIDER MIN/MAX BRIDGE */
1828 /*************************/
1831 * Set the minimum value of a Slider
1832 * @param id the id of the Slider
1833 * @param value the minimum value
1835 // TODO REMOVE ME (NO MORE USED IN JNI)
1836 public static void setSliderMinValue(int id, int value) {
1837 ((Slider) UIElementMapper.getCorrespondingUIElement(id)).setMinimumValue(value);
1841 * Set the maximum value of a Slider
1842 * @param id the id of the Widget
1843 * @param value the maximum value
1845 // TODO REMOVE ME (NO MORE USED IN JNI)
1846 public static void setSliderMaxValue(int id, int value) {
1847 ((Slider) UIElementMapper.getCorrespondingUIElement(id)).setMaximumValue(value);
1850 /*****************************/
1852 /* SLIDER ORIENTATION BRIDGE */
1854 /*****************************/
1857 * Set the slider orientation to vertical
1858 * @param id the id of the slider
1860 // TODO REMOVE ME (NO MORE USED IN JNI)
1861 public static void setSliderVertical(int id) {
1862 ((Slider) UIElementMapper.getCorrespondingUIElement(id)).setVertical();
1866 * Set the slider orientation to horizontal
1867 * @param id the id of the slider
1869 // TODO REMOVE ME (NO MORE USED IN JNI)
1870 public static void setSliderHorizontal(int id) {
1871 ((Slider) UIElementMapper.getCorrespondingUIElement(id)).setHorizontal();
1874 /******************/
1876 /* LISTBOX BRIDGE */
1878 /******************/
1881 * Set if more than one item can be selected in a ListBox
1882 * @param id the id of the ListBox
1883 * @param status true if multiple selection is enabled
1885 // TODO REMOVE ME (NO MORE USED IN JNI)
1886 public static void setListBoxMultipleSelectionEnabled(int id, boolean status) {
1887 ((ListBox) UIElementMapper.getCorrespondingUIElement(id)).setMultipleSelectionEnabled(status);
1891 * Get the text of all the list items
1892 * @param id the id of the ListBox
1893 * @return the text items
1894 * @see org.scilab.modules.gui.listbox.ListBox#getAllItemsText()
1896 // TODO REMOVE ME (NO MORE USED IN JNI)
1897 public static String[] getListBoxAllItemsText(int id) {
1898 return ((ListBox) UIElementMapper.getCorrespondingUIElement(id)).getAllItemsText();
1902 * Get the number of items in the list
1903 * @param id the id of the ListBox
1904 * @return the number of items
1905 * @see org.scilab.modules.gui.listbox.ListBox#getNumberOfItems()
1907 // TODO REMOVE ME (NO MORE USED IN JNI)
1908 public static int getListBoxNumberOfItems(int id) {
1909 return ((ListBox) UIElementMapper.getCorrespondingUIElement(id)).getNumberOfItems();
1913 * Set the text of the list items
1914 * @param id the id of the ListBox
1915 * @param text the text of the items
1916 * @see org.scilab.modules.gui.listbox.ListBox#setText(java.lang.String[])
1918 // TODO REMOVE ME (NO MORE USED IN JNI)
1919 public static void setListBoxText(int id, String[] text) {
1920 ((ListBox) UIElementMapper.getCorrespondingUIElement(id)).setText(text);
1924 * Adjusts the view so that the element given by index is displayed at the top of the ListBox.
1925 * @param id the id of the ListBox
1926 * @param index the index of the element to be displayed at the top of the ListBox.
1928 // TODO REMOVE ME (NO MORE USED IN JNI)
1929 public static void setListBoxListBoxTop(int id, int index) {
1930 ((ListBox) UIElementMapper.getCorrespondingUIElement(id)).setListBoxTop(index);
1934 * Gets the index of the element displayed at the top of the ListBox
1935 * @param id the id of the ListBox
1936 * @return the index of the element displayed at the top of the ListBox
1938 // TODO REMOVE ME (NO MORE USED IN JNI)
1939 public static int getListBoxListBoxTop(int id) {
1940 return ((ListBox) UIElementMapper.getCorrespondingUIElement(id)).getListBoxTop();
1943 /********************/
1945 /* POPUPMENU BRIDGE */
1947 /********************/
1950 * Get the text of all the PopupMenu items
1951 * @param id the id of the PopupMenu
1952 * @return the text items
1953 * @see org.scilab.modules.gui.popupmenu.PopupMenu#getAllItemsText()
1955 // TODO REMOVE ME (NO MORE USED IN JNI)
1956 public static String[] getPopupMenuAllItemsText(int id) {
1957 return ((PopupMenu) UIElementMapper.getCorrespondingUIElement(id)).getAllItemsText();
1961 * Get the number of items in the PopupMenu
1962 * @param id the id of the PopupMenu
1963 * @return the number of items
1964 * @see org.scilab.modules.gui.popupmenu.PopupMenu#getNumberOfItems()
1966 // TODO REMOVE ME (NO MORE USED IN JNI)
1967 public static int getPopupMenuNumberOfItems(int id) {
1968 return ((PopupMenu) UIElementMapper.getCorrespondingUIElement(id)).getNumberOfItems();
1972 * Set the text of the PopupMenu items
1973 * @param id the id of the PopupMenu
1974 * @param text the text of the items
1975 * @see org.scilab.modules.gui.popupmenu.PopupMenu#setText(java.lang.String[])
1977 // TODO REMOVE ME (NO MORE USED IN JNI)
1978 public static void setPopupMenuText(int id, String[] text) {
1979 ((PopupMenu) UIElementMapper.getCorrespondingUIElement(id)).setText(text);
1989 * Set the selected indices of the ListBox
1990 * @param id the id of the ListBox
1991 * @param indices the indices of the items to be selected
1993 // TODO REMOVE ME (NO MORE USED IN JNI)
1994 public static void setListBoxSelectedIndices(int id, int[] indices) {
1995 ((ListBox) UIElementMapper.getCorrespondingUIElement(id)).setSelectedIndices(indices);
1999 * Get the selected indices of the ListBox
2000 * @param id the id of the ListBox
2001 * @return the indices of the items selected
2003 // TODO REMOVE ME (NO MORE USED IN JNI)
2004 public static int[] getListBoxSelectedIndices(int id) {
2005 return ((ListBox) UIElementMapper.getCorrespondingUIElement(id)).getSelectedIndices();
2009 * Get the number of items selected in the ListBox
2010 * @param id the id of the ListBox
2011 * @return the number of items selected
2013 // TODO REMOVE ME (NO MORE USED IN JNI)
2014 public static int getListBoxSelectionSize(int id) {
2015 return ((ListBox) UIElementMapper.getCorrespondingUIElement(id)).getSelectionSize();
2019 * Set the selected index of the PopupMenu
2020 * @param id the id of the PopupMenu
2021 * @param index the index of the item to be selected
2023 // TODO REMOVE ME (NO MORE USED IN JNI)
2024 public static void setPopupMenuSelectedIndex(int id, int index) {
2025 ((PopupMenu) UIElementMapper.getCorrespondingUIElement(id)).setUserSelectedIndex(index);
2029 * Get the selected index of the PopupMenu
2030 * @param id the id of the PopupMenu
2031 * @return the index of the item selected
2033 // TODO REMOVE ME (NO MORE USED IN JNI)
2034 public static int getPopupMenuSelectedIndex(int id) {
2035 return ((PopupMenu) UIElementMapper.getCorrespondingUIElement(id)).getUserSelectedIndex();
2039 * Get the current value of the Slider
2040 * @param id the id of the Slider
2041 * @return the current value of the Slider
2043 // TODO REMOVE ME (NO MORE USED IN JNI)
2044 public static int getSliderValue(int id) {
2045 return ((Slider) UIElementMapper.getCorrespondingUIElement(id)).getValue();
2049 * Sets the current value of the Slider
2050 * @param id the id of the Slider
2051 * @param value the new value
2053 // TODO REMOVE ME (NO MORE USED IN JNI)
2054 public static void setSliderValue(int id, int value) {
2055 ((Slider) UIElementMapper.getCorrespondingUIElement(id)).setUserValue(value);
2059 * Set if the RadioButton is checked or not
2060 * @param id the id of the RadioButton
2061 * @param status true to set the RadioButton checked
2063 // TODO REMOVE ME (NO MORE USED IN JNI)
2064 public static void setRadioButtonChecked(int id, boolean status) {
2065 ((RadioButton) UIElementMapper.getCorrespondingUIElement(id)).setChecked(status);
2069 * Get the status of the RadioButton
2070 * @param id the id of the RadioButton
2071 * @return true if the RadioButton is checked
2073 // TODO REMOVE ME (NO MORE USED IN JNI)
2074 public static boolean isRadioButtonChecked(int id) {
2075 return ((RadioButton) UIElementMapper.getCorrespondingUIElement(id)).isChecked();
2079 * Set if the CheckBox is checked or not
2080 * @param id the id of the CheckBox
2081 * @param status true to set the CheckBox checked
2083 // TODO REMOVE ME (NO MORE USED IN JNI)
2084 public static void setCheckBoxChecked(int id, boolean status) {
2085 ((CheckBox) UIElementMapper.getCorrespondingUIElement(id)).setChecked(status);
2089 * Get the status of the CheckBox
2090 * @param id the id of the CheckBox
2091 * @return true if the CheckBox is checked
2093 // TODO REMOVE ME (NO MORE USED IN JNI)
2094 public static boolean isCheckBoxChecked(int id) {
2095 return ((CheckBox) UIElementMapper.getCorrespondingUIElement(id)).isChecked();
2105 * Set the Relief of the Widget
2106 * @param id the id of the Widget
2107 * @param reliefType the type of the relief to set (See ScilabRelief.java)
2109 // TODO REMOVE ME (NO MORE USED IN JNI)
2110 public static void setWidgetRelief(int id, String reliefType) {
2111 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setRelief(reliefType);
2115 * Set the Relief of the Frame
2116 * @param id the id of the Frame
2117 * @param reliefType the type of the relief to set (See ScilabRelief.java)
2119 // TODO REMOVE ME (NO MORE USED IN JNI)
2120 public static void setFrameRelief(int id, String reliefType) {
2121 ((Frame) UIElementMapper.getCorrespondingUIElement(id)).setRelief(reliefType);
2124 /******************/
2126 /* TOOLBAR BRIDGE */
2128 /******************/
2131 * Set the visibility of a Toolbar
2132 * @param parentUID the parent (figure or console) UID
2133 * @param status true to set the Toolbar visible
2135 public static void setToolbarVisible(String parentUID, boolean status) {
2136 SwingScilabTab parentTab = (SwingScilabTab) SwingView.getFromId(parentUID);
2137 if (parentTab != null) {
2138 parentTab.getToolBar().getAsSimpleToolBar().setVisible(status);
2139 BarUpdater.updateBars(parentTab.getParentWindowId(), parentTab.getMenuBar(),
2140 parentTab.getToolBar(), parentTab.getInfoBar(), parentTab.getName(), parentTab.getWindowIcon());
2145 * Get the visibility of a Toolbar
2146 * @param parentUID the parent (figure or console) UID
2147 * @return true to set the Toolbar visible
2149 public static boolean isToolbarVisible(String parentUID) {
2150 SwingScilabTab parentTab = (SwingScilabTab) SwingView.getFromId(parentUID);
2151 if (parentTab != null) {
2152 return parentTab.getToolBar().getAsSimpleToolBar().isVisible();
2158 /***********************/
2160 /* EVENTHANDLER BRIDGE */
2162 /***********************/
2165 * Set the event handler of the figure
2166 * @param figNum the figure
2167 * @param command the name of the Scilab function to call
2169 // TODO REMOVE ME (NO MORE USED IN JNI)
2170 public static void setEventHandler(int figNum, String command) {
2171 //FigureMapper.getCorrespondingFigure(figNum).getRendererProperties().setEventHandler(command);
2175 * Set the status of the event handler of the figure
2176 * @param figNum the figure
2177 * @param status is true to set the event handler active
2179 // TODO REMOVE ME (NO MORE USED IN JNI)
2180 public static void setEventHandlerEnabled(int figNum, boolean status) {
2181 //FigureMapper.getCorrespondingFigure(figNum).getRendererProperties().setEventHandlerEnabled(status);
2184 /******************/
2186 /* WAITBAR BRIDGE */
2188 /******************/
2191 * Set the WaitBar message (multi-line)
2192 * @param id the id of the waitBar
2193 * @param message the message of the waitBar
2195 // TODO REMOVE ME (NO MORE USED IN JNI)
2196 public static void setWaitBarMessage(int id, String[] message) {
2197 ((WaitBar) UIElementMapper.getCorrespondingUIElement(id)).setMessage(message);
2201 * Set the WaitBar value
2202 * @param id the id of the waitBar
2203 * @param value the value of the waitBar
2205 // TODO REMOVE ME (NO MORE USED IN JNI)
2206 public static void setWaitBarValue(int id, int value) {
2207 ((WaitBar) UIElementMapper.getCorrespondingUIElement(id)).setValue(value);
2212 * @param id the id of the WaitBar to destroy
2214 // TODO REMOVE ME (NO MORE USED IN JNI)
2215 public static void destroyWaitBar(int id) {
2216 ((WaitBar) UIElementMapper.getCorrespondingUIElement(id)).close();
2220 * Indicates if the total execution time is known
2221 * @param id the id of the WaitBar to destroy
2222 * @param status true if the total progress time in unknown
2224 // TODO REMOVE ME (NO MORE USED IN JNI)
2225 public static void setWaitBarIndeterminateMode(int id, boolean status) {
2226 ((WaitBar) UIElementMapper.getCorrespondingUIElement(id)).setIndeterminateMode(status);
2229 /**********************/
2231 /* HELPBROWSER BRIDGE */
2233 /**********************/
2236 * Launch Scilab help browser if not already created
2237 * @param helps help chapters and directories
2238 * @param language Scilab current language
2240 public static void launchHelpBrowser(String[] helps, String language) {
2241 ScilabHelpBrowser.createHelpBrowser(helps, language);
2242 ScilabHelpBrowser.startHomePage();
2246 * Search a keyword in Scilab Help Browser
2247 * @param keyword the keyword to search
2248 * @param helps help chapters and directories
2249 * @param language Scilab current language
2250 * @param fullText true for a full-text search
2252 public static void searchKeyword(String[] helps, String keyword, String language, boolean fullText) {
2254 HelpBrowser helpBrowser = ScilabHelpBrowser.createHelpBrowser(helps, language);
2255 if (helpBrowser != null) {
2256 helpBrowser.fullTextSearch(keyword);
2259 HelpBrowser helpBrowser = ScilabHelpBrowser.createHelpBrowser(helps, language);
2260 if (helpBrowser != null) {
2261 helpBrowser.searchKeywork(keyword);
2267 * Open HelpBrowser on the page with the given xmlID
2268 * @param xmlID the xml id
2270 public static void openHelp(String xmlID) {
2271 HelpBrowser helpBrowser = ScilabHelpBrowser.createHelpBrowser(null, ScilabCommons.getlanguage());
2272 if (helpBrowser != null) {
2273 helpBrowser.searchKeywork(xmlID);
2278 * Close Scilab Help Browser
2280 public static void closeHelpBrowser() {
2281 ScilabHelpBrowser.getHelpBrowser().close();
2285 * Show search field in Scilab Help Browser
2287 public static void showSearchFieldInHelp() {
2288 ScilabHelpBrowser.getHelpBrowser().showSearchField();
2292 * Increase the font in the help viewer
2294 public static void increaseFontInHelpViewer() {
2295 ScilabHelpBrowser.getHelpBrowser().increaseFont();
2299 * Decrease the font in the help viewer
2301 public static void decreaseFontInHelpViewer() {
2302 ScilabHelpBrowser.getHelpBrowser().decreaseFont();
2312 * Open a Browser on Scilab Web Site
2314 public static void openScilabWebSite() {
2315 WebBrowser.openUrl("http://www.scilab.org/");
2319 * Open a Browser on Wiki Web Site
2321 public static void openWiki() {
2322 WebBrowser.openUrl("http://wiki.scilab.org/");
2326 * Open a Browser on ATOMS Web Site
2328 public static void openAtomsScilab() {
2329 WebBrowser.openUrl("http://atoms.scilab.org/");
2333 * Open a Browser on File Exchange Web Site
2335 public static void openFileExchange() {
2336 WebBrowser.openUrl("http://fileexchange.scilab.org/");
2340 * Open a Browser on Bugzilla Web Site
2342 public static void openBugzilla() {
2343 WebBrowser.openUrl("http://bugzilla.scilab.org/");
2347 * Open a Browser on Forge Web Site
2349 public static void openForge() {
2350 WebBrowser.openUrl("http://forge.scilab.org/");
2354 * Open a Browser on Scilab Online Help
2356 public static void openOnlineHelp() {
2357 WebBrowser.openUrl("http://help.scilab.org/");
2361 * Open a Browser on Mailing List info
2363 public static void openMailingList() {
2364 WebBrowser.openUrl("http://www.scilab.org/communities/developer_zone/tools/mailing_list");
2368 * Open a Browser on Mailing List Archives
2370 public static void openMailingListArchives() {
2371 WebBrowser.openUrl("http://mailinglists.scilab.org/");
2375 * Open a Browser on S/E
2377 public static void openSE() {
2378 WebBrowser.openUrl("http://www.scilab-enterprises.com/");
2381 /***************************/
2383 /* JAVA CALLBACKS FOR GUIS */
2385 /***************************/
2388 * Select all the console contents
2390 public static void selectAllConsoleContents() {
2391 ScilabConsole.getConsole().selectAll();
2395 * Select all the console contents
2397 public static void helpOnTheKeyword() {
2398 ScilabConsole.getConsole().helpOnTheKeyword();
2402 * Put the console selected text in the clipboard
2404 public static void copyConsoleSelection() {
2405 ScilabConsole.getConsole().copyToClipboard();
2409 * Cut the console selected text in the clipboard
2411 public static void cutConsoleSelection() {
2412 ScilabConsole.getConsole().cutSelection();
2416 * Paste clipboard contents in Console input line
2418 public static void pasteClipboardIntoConsole() {
2419 ScilabConsole.getConsole().pasteClipboard();
2423 * Make the clipboard contents empty
2425 public static void emptyClipboard() {
2426 Transferable contents = new StringSelection("");
2427 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
2431 * Evaluate the selection with echo
2433 public static void evaluateSelectionWithEcho() {
2434 ScilabConsole.getConsole().evaluateSelectionWithEcho();
2438 * Evaluate the selection with no echo
2440 public static void evaluateSelectionWithNoEcho() {
2441 ScilabConsole.getConsole().evaluateSelectionWithNoEcho();
2445 * Opens a dialog to selected a new font for the console
2447 public static void changeConsoleFont() {
2448 FontChooser fontChooser = ScilabFontChooser.createFontChooser(ScilabConsole.getConsole().getFont());
2449 fontChooser.displayAndWait();
2451 Font selectedFont = fontChooser.getSelectedFont();
2453 if (selectedFont != null) {
2454 /* Change console font */
2455 ScilabConsole.getConsole().setFont(selectedFont);
2457 /* Save new settings */
2458 ConfigManager.saveFont(selectedFont);
2463 * Unblock the console if it is in "Continue display..." mode
2465 public static void unblockConsole() {
2466 SwingScilabConsole sciConsole = ((SwingScilabConsole) ScilabConsole.getConsole().getAsSimpleConsole());
2467 sciConsole.unblock();
2471 * Opens a dialog to selected a new Foreground Color for the console
2473 public static void changeConsoleForeground() {
2474 ColorChooser colorChooser = ScilabColorChooser.createColorChooser(ScilabConsole.getConsole().getForeground());
2475 colorChooser.setTitle(Messages.gettext("Console Font..."));
2476 colorChooser.displayAndWait();
2478 Color selectedColor = colorChooser.getSelectedColor();
2480 if (selectedColor != null) {
2481 /* Change console foreground */
2482 ScilabConsole.getConsole().setForeground(selectedColor);
2484 /* Save new settings */
2485 ConfigManager.saveConsoleForeground(selectedColor);
2490 * Opens a dialog to selected a new Background Color for the console
2492 public static void changeConsoleBackground() {
2493 ColorChooser colorChooser = ScilabColorChooser.createColorChooser(ScilabConsole.getConsole().getBackground());
2494 colorChooser.setTitle(Messages.gettext("Console Background..."));
2495 colorChooser.displayAndWait();
2497 Color selectedColor = colorChooser.getSelectedColor();
2499 if (selectedColor != null) {
2500 /* Change console background */
2501 ScilabConsole.getConsole().setBackground(selectedColor);
2503 /* Save new settings */
2504 ConfigManager.saveConsoleBackground(selectedColor);
2509 * Display a dialog to print the console text contents
2511 public static void printConsoleContents() {
2513 SciConsole scilabConsole = ((SciConsole) ScilabConsole.getConsole().getAsSimpleConsole());
2514 Document doc = ((JEditorPane) scilabConsole.getConfiguration().getOutputView()).getDocument();
2515 String textToPrint = null;
2517 /* Text selected in the input */
2518 String strInputSelected = ((JTextPane) scilabConsole.getConfiguration().getInputCommandView()).getSelectedText();
2519 /* Text selected in the output */
2520 String strOutputSelected = ((JEditorPane) scilabConsole.getConfiguration().getOutputView()).getSelectedText();
2523 textToPrint = doc.getText(0, doc.getLength());
2524 } catch (BadLocationException e) {
2525 e.printStackTrace();
2527 if (strInputSelected != null) {
2528 printString(strInputSelected, new String(CONSOLE));
2529 } else if (strOutputSelected != null) {
2530 printString(strOutputSelected, new String(CONSOLE));
2532 printString(textToPrint, new String(CONSOLE));
2537 * Print a character string
2538 * @param theString the string to print
2539 * @param pageHeader header for printed pages
2540 * @return execution status
2542 public static boolean printString(String theString, String pageHeader) {
2543 return PrinterHelper.printString(theString, pageHeader);
2547 * Display a dialog to print a file
2548 * @param fileName the name of the file
2549 * @return execution status
2551 public static boolean printFile(String fileName) {
2552 return PrinterHelper.printFile(fileName);
2556 * Display a dialog to print a figure (Called from graphics figures menus)
2557 * @param figID the ID of the figure to print
2558 * @return execution status
2560 public static boolean printFigure(String figID) {
2561 return printFigure(figID, true, true);
2565 * Display a dialog to print a figure
2566 * @param figID the ID of the figure to print
2567 * @param postScript true to print in postscript mode
2568 * @param displayDialog true to display a print setup dialog
2569 * @return execution status
2571 public static boolean printFigure(String figID, boolean postScript, boolean displayDialog) {
2572 // Get the PrinterJob object
2573 PrinterJob printerJob = PrinterJob.getPrinterJob();
2575 boolean userOK = true;
2576 if (displayDialog) {
2577 userOK = printerJob.printDialog(scilabPageFormat);
2581 //If the OS is Windows
2582 if (isWindowsPlateform()) {
2583 Figure figure = (Figure) GraphicController.getController().getObjectFromId(figID);
2584 int figureID = figure.getId();
2585 SwingScilabCanvas canvas;
2586 canvas = ((SwingScilabTab) SwingView.getFromId(figID)).getContentCanvas();
2587 ScilabPrint scilabPrint = new ScilabPrint(canvas.dumpAsBufferedImage(), printerJob, scilabPageFormat);
2588 if (scilabPrint != null) {
2594 //If the OS is Linux
2596 DocFlavor printDocFlavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
2597 String fileExtension = ".ps";
2600 String tmpPrinterFile = File.createTempFile("scilabfigure", "").getAbsolutePath();
2601 // Export image to PostScript
2602 if (((PrintRequestAttribute) scilabPageFormat.get(OrientationRequested.class)) == OrientationRequested.PORTRAIT) {
2603 FileExporter.fileExport(figID,
2604 tmpPrinterFile + fileExtension,
2605 "PS", 1, 0); // 1 is the quality. Useless in this context
2607 FileExporter.fileExport(figID,
2608 tmpPrinterFile + fileExtension,
2609 "PS", 1, 1); // 1 is the quality. Useless in this context
2613 FileInputStream psStream = null;
2616 psStream = new FileInputStream(tmpPrinterFile + fileExtension);
2617 } catch (FileNotFoundException ffne) {
2618 ffne.printStackTrace();
2622 Doc myDoc = new SimpleDoc(psStream, printDocFlavor, null);
2623 PrintService printService = printerJob.getPrintService();
2625 if (printService == null) {
2626 // Could not find the print service
2627 MessageBox messageBox = ScilabMessageBox.createMessageBox();
2628 messageBox.setMessage(Messages.gettext("No print service found."));
2629 messageBox.setModal(true);
2630 messageBox.setIcon("error");
2631 messageBox.displayAndWait();
2634 DocPrintJob job = printService.createPrintJob();
2636 // Remove Orientation option from page setup because already managed in FileExporter
2637 PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(scilabPageFormat);
2638 aset.add(OrientationRequested.PORTRAIT);
2639 job.print(myDoc, aset);
2641 } catch (IOException e) {
2642 System.err.println("Could not create temporary file " + e.getLocalizedMessage());
2644 } catch (PrintException e) {
2645 e.printStackTrace();
2654 * Display a page setup dialog for printing
2655 * @return true if the user clicked the OK button
2657 public static boolean pageSetup() {
2658 // Get the PrinterJob object
2659 PrinterJob job = PrinterJob.getPrinterJob();
2661 // Get the default page format, then allow the user to modify it
2662 return (job.pageDialog(scilabPageFormat) != null);
2665 /***********************/
2667 /* FONT CHOOSER BRIDGE */
2669 /***********************/
2672 * Set the default font name for a FileChooser
2673 * @param id the id of the FileChooser
2674 * @param fontName the name of the font
2676 public static void setFontChooserFontName(int id, String fontName) {
2677 ((FontChooser) UIElementMapper.getCorrespondingUIElement(id)).setDefaultFontName(fontName);
2681 * Set the default font size for a FileChooser
2682 * @param id the id of the FileChooser
2683 * @param fontSize the size of the font
2685 public static void setFontChooserFontSize(int id, int fontSize) {
2686 ((FontChooser) UIElementMapper.getCorrespondingUIElement(id)).setDefaultFontSize(fontSize);
2690 * Set the default bold attribute for a FileChooser
2691 * @param id the id of the FileChooser
2692 * @param bold the bold attribute of the font
2694 public static void setFontChooserBold(int id, boolean bold) {
2695 ((FontChooser) UIElementMapper.getCorrespondingUIElement(id)).setDefaultBold(bold);
2699 * Set the default italic attribute for a FileChooser
2700 * @param id the id of the FileChooser
2701 * @param italic the italic attribute of the font
2703 public static void setFontChooserItalic(int id, boolean italic) {
2704 ((FontChooser) UIElementMapper.getCorrespondingUIElement(id)).setDefaultItalic(italic);
2708 * Get the selected font name for a FileChooser
2709 * @param id the id of the FileChooser
2710 * @return the name of the font
2712 public static String getFontChooserFontName(int id) {
2713 Font selectedFont = ((FontChooser) UIElementMapper.getCorrespondingUIElement(id)).getSelectedFont();
2714 if (selectedFont != null) {
2715 return selectedFont.getFamily();
2722 * Get the selected font size for a FileChooser
2723 * @param id the id of the FileChooser
2724 * @return the size of the font
2726 public static int getFontChooserFontSize(int id) {
2727 return ((FontChooser) UIElementMapper.getCorrespondingUIElement(id)).getSelectedFont().getSize();
2731 * Get the selected bold attribute for a FileChooser
2732 * @param id the id of the FileChooser
2733 * @return the bold attribute of the font
2735 public static boolean getFontChooserBold(int id) {
2736 return ((FontChooser) UIElementMapper.getCorrespondingUIElement(id)).getSelectedFont().isBold();
2740 * Get the selected italic attribute for a FileChooser
2741 * @param id the id of the FileChooser
2742 * @return the italic attribute of the font
2744 public static boolean getFontChooserItalic(int id) {
2745 return ((FontChooser) UIElementMapper.getCorrespondingUIElement(id)).getSelectedFont().isItalic();
2749 * Display this chooser and wait for user selection
2750 * @param id the id of the FontChooser
2752 public static void fontChooserDisplayAndWait(int id) {
2753 ((FontChooser) UIElementMapper.getCorrespondingUIElement(id)).displayAndWait();
2756 /************************/
2758 /* COLOR CHOOSER BRIDGE */
2760 /************************/
2763 * Set the title of a ColorChooser
2764 * @param id the id of the ColorChooser
2765 * @param title the title
2767 public static void setColorChooserTitle(int id, String title) {
2768 ((ColorChooser) UIElementMapper.getCorrespondingUIElement(id)).setTitle(title);
2772 * Set the default Color for a ColorChooser
2773 * @param id the id of the ColorChooser
2774 * @param rgb the default color
2776 public static void setColorChooserDefaultColor(int id, int[] rgb) {
2777 ((ColorChooser) UIElementMapper.getCorrespondingUIElement(id)).setDefaultColor(new Color(rgb[0], rgb[1], rgb[2]));
2781 * Get the selected Color for a ColorChooser
2782 * @param id the id of the ColorChooser
2783 * @return the selected color
2785 public static int[] getColorChooserSelectedColor(int id) {
2786 Color selectedColor = ((ColorChooser) UIElementMapper.getCorrespondingUIElement(id)).getSelectedColor();
2787 int[] returnedValues = new int[NB_COLORS];
2788 if (selectedColor != null) {
2789 returnedValues[0] = selectedColor.getRed();
2790 returnedValues[1] = selectedColor.getGreen();
2791 returnedValues[2] = selectedColor.getBlue();
2793 returnedValues[0] = -1;
2794 returnedValues[1] = -1;
2795 returnedValues[2] = -1;
2797 return returnedValues;
2802 * Display this chooser and wait for user selection
2803 * @param id the id of the ColorChooser
2805 public static void colorChooserDisplayAndWait(int id) {
2806 ((ColorChooser) UIElementMapper.getCorrespondingUIElement(id)).displayAndWait();
2809 /******************/
2811 /* WIDGET VISIBLE */
2813 /******************/
2816 * Set the visibility of the Widget
2817 * @param id the id of the Widget
2818 * @param status the new status
2820 // TODO REMOVE ME (NO MORE USED IN JNI)
2821 public static void setWidgetVisible(int id, boolean status) {
2822 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setVisible(status);
2826 * Set the visibility of the Frame
2827 * @param id the id of the Frame
2828 * @param status the new status
2830 // TODO REMOVE ME (NO MORE USED IN JNI)
2831 public static void setFrameVisible(int id, boolean status) {
2832 ((Frame) UIElementMapper.getCorrespondingUIElement(id)).setVisible(status);
2836 * Get the visibility of the Widget
2837 * @param id the id of the Widget
2838 * @return the status
2840 // TODO REMOVE ME (NO MORE USED IN JNI)
2841 public static boolean isWidgetVisible(int id) {
2842 return ((Widget) UIElementMapper.getCorrespondingUIElement(id)).isVisible();
2846 * Get the visibility of the Frame
2847 * @param id the id of the Frame
2848 * @return the status
2850 // TODO REMOVE ME (NO MORE USED IN JNI)
2851 public static boolean isFrameVisible(int id) {
2852 return ((Frame) UIElementMapper.getCorrespondingUIElement(id)).isVisible();
2862 * Set the enable of the Widget
2863 * @param id the id of the Widget
2864 * @param status the new status
2866 // TODO REMOVE ME (NO MORE USED IN JNI)
2867 public static void setWidgetEnable(int id, boolean status) {
2868 ((Widget) UIElementMapper.getCorrespondingUIElement(id)).setEnabled(status);
2872 * Set the enable of the Frame
2873 * @param id the id of the Frame
2874 * @param status the new status
2876 // TODO REMOVE ME (NO MORE USED IN JNI)
2877 public static void setFrameEnable(int id, boolean status) {
2878 ((Frame) UIElementMapper.getCorrespondingUIElement(id)).setEnabled(status);
2882 * Get the enable of the Widget
2883 * @param id the id of the Widget
2884 * @return the status
2886 // TODO REMOVE ME (NO MORE USED IN JNI)
2887 public static boolean isWidgetEnable(int id) {
2888 return ((Widget) UIElementMapper.getCorrespondingUIElement(id)).isEnabled();
2892 * Get the visibility of the Frame
2893 * @param id the id of the Frame
2894 * @return the status
2896 // TODO REMOVE ME (NO MORE USED IN JNI)
2897 public static boolean isFrameEnable(int id) {
2898 return ((Frame) UIElementMapper.getCorrespondingUIElement(id)).isEnabled();
2908 * Set the Checked status of the Menu
2909 * @param id the id of the Menu
2910 * @param status the new status
2912 // TODO REMOVE ME (NO MORE USED IN JNI)
2913 public static void setMenuChecked(int id, boolean status) {
2914 if (UIElementMapper.getCorrespondingUIElement(id) instanceof CheckBoxMenuItem) {
2915 ((CheckBoxMenuItem) UIElementMapper.getCorrespondingUIElement(id)).setChecked(status);
2916 } else if (UIElementMapper.getCorrespondingUIElement(id) instanceof MenuItem) {
2917 ((MenuItem) UIElementMapper.getCorrespondingUIElement(id)).setChecked(status);
2919 ((Menu) UIElementMapper.getCorrespondingUIElement(id)).setChecked(status);
2924 * Get the Checked status of the Menu
2925 * @param id the id of the Menu
2926 * @return the status
2928 // TODO REMOVE ME (NO MORE USED IN JNI)
2929 public static boolean isMenuChecked(int id) {
2930 return ((Menu) UIElementMapper.getCorrespondingUIElement(id)).isChecked();
2933 /************************/
2935 /* CLIPBOARD MANAGEMENT */
2937 /************************/
2940 * Get the contents of the clipboard
2941 * @return the string contained in the clipboard or null
2943 public static String getClipboardContents() {
2944 // Gets the contents of the clipboard
2945 Toolkit toolkit = Toolkit.getDefaultToolkit();
2946 Clipboard systemClipboard = toolkit.getSystemClipboard();
2947 String clipboardContents = "";
2949 // Verify that clibpboard data is of text type
2950 boolean dataAvailable;
2952 dataAvailable = systemClipboard.isDataFlavorAvailable(DataFlavor.stringFlavor);
2953 } catch (IllegalStateException exception) {
2954 return clipboardContents;
2957 // Exit if text data not available
2958 if (!dataAvailable) {
2959 return clipboardContents;
2964 clipboardContents = (String) systemClipboard.getData(DataFlavor.stringFlavor);
2965 } catch (UnsupportedFlavorException e1) {
2966 // Should never be here
2967 e1.printStackTrace();
2968 } catch (IOException e1) {
2969 // Should never be here
2970 e1.printStackTrace();
2973 return clipboardContents;
2977 * Set the contents of the clipboard
2978 * @param text the string to put in the clipboard
2980 public static void setClipboardContents(String text) {
2981 Transferable contents = new StringSelection(text);
2982 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
2986 * Copy figure to clipboard
2987 * @param figID the ID of the figure
2989 public static void copyFigureToClipBoard(int figID) {
2990 Image figureImage = ImageExporter.imageExport(figID);
2991 Transferable clipboardImage = new ClipboardImage(figureImage);
2992 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(clipboardImage, null);
2996 * Class used to store Images in the clipboard
2998 public static class ClipboardImage implements Transferable {
2999 private final Image image;
3002 * Default constructor
3003 * @param image the image
3005 public ClipboardImage(Image image) {
3010 * DataFlavors of this transferable
3011 * @return the DataFlavors accepeted
3014 public DataFlavor[] getTransferDataFlavors() {
3015 return new DataFlavor[] {DataFlavor.imageFlavor};
3019 * Test supproted DataFlavors
3020 * @param flavor the flavor to test
3021 * @return true if the flavor is supported
3024 public boolean isDataFlavorSupported(DataFlavor flavor) {
3025 return DataFlavor.imageFlavor.equals(flavor);
3029 * Get the contents of this transferable
3030 * @param flavor the flavor to test
3031 * @return the contents
3032 * @throws UnsupportedFlavorException if the flavor is not supported by this transferable
3035 public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
3036 if (!DataFlavor.imageFlavor.equals(flavor)) {
3037 throw new UnsupportedFlavorException(flavor);
3050 * Get the screen resolution
3051 * @return the number of dot per inch
3053 public static int getScreenResolution() {
3054 return Toolkit.getDefaultToolkit().getScreenResolution();
3058 * Get the screen Width in pixels
3059 * @return the screen Width
3061 public static double getScreenWidth() {
3062 return Toolkit.getDefaultToolkit().getScreenSize().getWidth();
3066 * Get the screen Height in pixels
3067 * @return the screen Height
3069 public static double getScreenHeight() {
3070 return Toolkit.getDefaultToolkit().getScreenSize().getHeight();
3074 * Get the screen Depth
3075 * @return the screen Depth
3077 public static int getScreenDepth() {
3078 return Toolkit.getDefaultToolkit().getColorModel().getPixelSize();
3082 * Give the focus to a uicontrol
3083 * @param uicontrolUID the uicontrolUID of the Widget
3085 public static void requestFocus(String uicontrolUID) {
3086 SwingViewObject uicontrol = SwingView.getFromId(uicontrolUID);
3087 if (uicontrol instanceof SwingScilabFrame) {
3088 ((SwingScilabFrame) uicontrol).requestFocus();
3090 ((Widget) uicontrol).requestFocus();
3096 * Raise the window specified by the user
3097 * @param id the id of the figure
3099 public static void raiseWindow(int id) {
3100 /*((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(id).getRendererProperties()).getParentTab().getParentWindow().raise();
3101 ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(id).getRendererProperties()).getParentTab().setCurrent();*/
3105 * @return true if the os is windows, false otherwise
3107 public static boolean isWindowsPlateform() {
3109 return System.getProperty("os.name").toLowerCase().contains("windows");
3113 * Change object used for graphic figure (GLCanvas or GLJPanel)
3114 * @param onOrOff true to set GLCanvas display
3116 public static void useCanvasForDisplay(boolean onOrOff) {
3117 SwingScilabCanvasImpl.switchToGLCanvas(onOrOff);
3121 * Get object used for graphic figure (GLCanvas or GLJPanel)
3122 * @return true if GLCanvas display is set
3124 public static boolean useCanvasForDisplay() {
3125 return SwingScilabCanvasImpl.isGLCanvasEnabled();
3129 * Display Scilab about box
3131 public static void scilabAboutBox() {
3132 ScilabAboutBox.displayAndWait();
3135 /******************/
3137 /* UITABLE BRIDGE */
3139 /******************/
3142 * Sets the column names for the uitable
3144 // TODO REMOVE ME (NO MORE USED IN JNI)
3145 public static void setUiTableColnames(int id, String text) {
3146 //((UiTable) UIElementMapper.getCorrespondingUIElement(id)).setColnames(text);
3150 * Sets the row names for the uitable
3152 // TODO REMOVE ME (NO MORE USED IN JNI)
3153 public static void setUiTableRownames(int id, String text) {
3154 //((UiTable) UIElementMapper.getCorrespondingUIElement(id)).setRownames(text);
3158 * Sets the data for the uitable
3160 // TODO REMOVE ME (NO MORE USED IN JNI)
3161 public static void setUiTableData(int id, String text) {
3162 ((UiTable) UIElementMapper.getCorrespondingUIElement(id)).setData(text);
3165 /******************/
3167 /* UITABLE BRIDGE */
3169 /******************/
3171 // TODO REMOVE ME (NO MORE USED IN JNI)
3172 public static void setUiTreeData(int id, String[] text) {
3173 ((UiDisplayTree) UIElementMapper.getCorrespondingUIElement(id)).setData(text);
3176 public static void fireClosingFinished(String figUID) {
3177 SwingScilabTab parentTab = (SwingScilabTab) SwingView.getFromId(figUID);
3178 ClosingOperationsManager.removeFromDunnoList(parentTab);