روش های مرتبط با رابط کاربری گرافیکی

روش های مرتبط با رابط کاربری گرافیکی

روش های مرتبط با رابط کاربری گرافیکی
روش‌های مرتبط با رابط کاربری گرافیکی (GUI) برای نمایش جعبه‌های محاوره‌ای با پیام‌ها، ویرایش اشیاء فرم و محتوای رابط کاربر، دریافت ویژگی‌های زمان اجرا رابط کاربری برنامه و روش‌های در حال اجرا استفاده می‌شوند.

 
Name
Syntax
Description
Call a method directly
<methodName>()
Call a method from the Methods list by using its name, for example, method1()method2().
callMethod
callMethod(String name)
Alternate way to call a method from the Methods list; used internally and in cases of name collisions.
useGraphics
useGraphics(ModelEntity entity, String name)
useGraphics(ModelEntity entity, FormObject graphics)
Plots the given entity (Plot Group, Geometry, Mesh, Explicit Selection or Player Animation) in the graphics form object given by the name, name path, or graphics form object in the second argument.
openForm
openForm(String name)
Shows the form with the given name in the current main window. In a single window application, the form replaces the current one. In an application with subwindows, the form must exist in the main window layout. If not, it will not be opened. Showing a form that is already open will only activate the form.
closeForm
closeForm(String name)
Closes the form with the given name. Closing forms is only possible in applications using subwindows. This method is not applicable for single window applications.
closeDialog
closeDialog(String name)
Closes the form, shown as a dialog box, with the given name.
dialog
dialog(String name)
Shows the form with the given name as a dialog box. Equivalent to the dialog method of a Form object; see below.
alert
alert(String text)
Stops execution and displays an alert message with the given text.
alert
alert(String text, String title)
Stops execution and displays an alert message with the given text and title.
confirm
String confirm(String text)
Stops execution and displays a confirmation dialog box with the given text. It also displays two buttons, “Yes” and “No”. The method returns “Yes” or “No” depending on what the user clicks.
confirm
String confirm(String text, String title)
Stops execution and displays a confirmation dialog box with the given text and title. It also displays two buttons, “Yes” and “No”. The method returns “Yes” or “No” depending on what the user clicks.
confirm
String confirm(String text, String title, String yes, String no)
Stops execution and displays a confirmation dialog box with the given text and title. It also displays two buttons with the given strings as labels. The method returns the label of the button that the user clicks.
confirm
String confirm(String text, String title, String yes, String no, String cancel)
Stops execution and displays a confirmation dialog box with the given text and title. It also displays three buttons with the given strings as labels. The method returns the label of the button that the user clicks.
error
error(String message)
Stops execution and opens an error dialog box with the given message.
error
error(String message, Throwable cause)
Stops execution and opens an error dialog box with the given message including the underlying cause of class Throwable, the general Java exception class, or one of its subclasses, such as RuntimeException. This can be used to “wrap” native COMSOL Multiphysics error messages with custom error messages.
request
String request(String text)
Stops execution and displays a dialog box with a text field, requesting input from the user. The given text is the label of the text field. The method returns the entered text or null if the cancel button is clicked.
request
String request(String text, String defaultString)
Stops execution and displays a dialog box with a text field, requesting input from the user. The given text is the label of the text field and the default string is the text initially shown in the text field. The method returns the entered text or null if the cancel button is clicked.
request
String request(String text, String title, String defaultString)
Stops execution and displays a dialog box with a text field, requesting input from the user. The given text is the label of the text field, the default string is the text initially shown in the text field, and the title is the title of the dialog box. The method returns the entered text or null if the cancel button is clicked.
message
message(String message)
Sends a message to the message log if available in the application.
message
message(arg)
Sends a message arg to the message log. For an application this requires that a message log is added to the application user interface. The input argument arg can be a scalar, 1D array, or 2D array of the types string, double, int or Boolean.
clearLog
clearLog()
Clears the log window.
clearMessageLog
clearMessageLog()
Clears the message log window.
evaluateToResultsTable
evaluateToResultsTable(NumericalFeature entity, String name, boolean clear)
evaluateToResultsTable(NumericalFeature entity, FormObject graphics, boolean clear)
Evaluates the given entity, a Derived Value, in the table object given by the name, name path, or graphics form object in the second argument, which will then be the default target for the evaluations of the Derived Value. If the third argument is true, the table is cleared before adding the new data, otherwise the data is appended.
evaluateToDoubleArray2D
double[][] evaluateToDoubleArray2D(NumericalFeature entity)
Evaluates the given entity, a Derived Value, and returns the non-parameter column part of the real table that is produced as a double matrix. All settings in the numerical feature are respected, but those in the current table connected to the numerical feature are ignored.
evaluateToIntegerArray2D
int[][] evaluateToIntegerArray2D(NumericalFeature entity)
Evaluates the given entity, a Derived Value, and returns the non-parameter column part of the real table that is produced as an integer matrix. All settings in the numerical feature are respected, but those in the current table connected to the numerical feature are ignored.
evaluateToStringArray2D
String[][] evaluateToStringArray2D(NumericalFeature entity)
Evaluates the given entity, a Derived Value, and returns the non-parameter column part of the, potentially complex, table that is produced as a string matrix. All settings in the numerical feature are respected but those in the current table connected to the numerical feature are ignored.
useResultsTable
useResultsTable(TableFeature tableFeature, String resultsTable)
useResultsTable(TableFeature tableFeature, FormObject resultsTable)
Shows the values from the tableFeature in the resultsTable form object.
getChoiceList
ChoiceList getChoiceList(String name)
Returns an object of the type ChoiceList, representing a choice list node under the declarations branch. The type ChoiceList has methods that make it easier to change the matrix value with respect to changing and accessing values and display names individually.
setFormObjectEnabled
setFormObjectEnabled(String name, boolean enabled)
Sets the enable state for the form object specified by the name or name path.
setFormObjectVisible
setFormObjectVisible(String name, boolean visible)
Sets the visible state for the form object specified by the name or name path.
setFormObjectText
setFormObjectText(String name, String text)
Sets the text for the form object specified by the name or name path in the second argument. This method throws an error if it is impossible to set a text for the specified form object.
setFormObjectEditable
setFormObjectEditable(String name, boolean editable)
Sets the editable state for the form object specified by the name or name path. This functionality is only available for text field objects.
setMenuBarItemEnabled
setMenuBarItemEnabled(String name, boolean enabled)
Sets the enable state for the menu bar item specified by the name or name path (from menu bar) in the first argument.
setMainToolbarItemEnabled
setMainToolbarItemEnabled(String name, boolean enabled)
Sets the enable state for the main toolbar item specified by the name or name path (from main toolbar) in the first argument.
setFileMenuItemEnabled
setFileMenuItemEnabled(String name, boolean enabled)
Sets the enable state for the file menu item specified by the name or name path (from file menu) in the first argument.
setRibbonItemEnabled
setRibbonItemEnabled(String name, boolean enabled)
Sets the enable state for the ribbon item specified by the name or name path (from main window) in the first argument.
setToolbarItemEnabled
setToolbarItemEnabled(String name, boolean enabled)
Sets the enable state for the toolbar form object item specified by the name or name path in the first argument.
useView
useView(View view, String name)
useView(View view, FormObject graphics)
Applies a view to the graphics contents given by the name, name path, or graphics form object in the second argument.
resetView
resetView(String name)
resetView(FormObject graphics)
Resets the view to its initial state in the graphics contents given by the name, name path, or graphics form object in the second argument.
getView
ViewBase getView(String name)
ViewBase getView(FormObject graphics)
Returns the view currently used by the graphics contents given by the name, name path, or graphics form object in the second argument.
goToView
goToView(String name);
Goes to a standard view in main graphics window. The parameter name is one of the view orientation strings in the following list: “xy”,”xz”,”yx”,”yz”,”zx”,”zy”.
goToView
goToView(String name, String graphicsname);
Goes to a standard view in the given graphics form object graphicsname.
goToView
goToView(String name, FormObject graphics);
Goes to standard view in the given graphics form object graphics.
setWebPageSource
setWebPageSource(String name, String source)
Sets the source for the form object specified by the name or name path in the first argument. This method throws an error if the name does not refer to a Web Page form object.
getScreenHeight
int getScreenHeight()
Returns the height in pixels of the primary screen on client system, or of the browser window if Web Client is used.
getScreenWidth
int getScreenWidth()
Returns the width in pixels of the primary screen on client system, or of the browser window if Web Client is used.
storeChanges
storeChanges(String form)
Commits the values entered in a dialog box having On request enabled. The method takes the name of the form as its argument.

هشدارها و پیام ها
روش‌ها هشدار ، تأیید و درخواست یک کادر محاوره‌ای با یک رشته متن و ورودی اختیاری کاربر را نمایش می‌دهند. مثال زیر از تایید استفاده می‌کند تا از کاربر بپرسد که آیا یک حل‌کننده مستقیم یا تکراری باید در یک برنامه کاربردی استفاده شود. بر اساس پاسخ، تابع هشدار سپس برای نشان دادن نیاز تخمینی حافظه برای نوع حل کننده انتخاب شده در یک کادر محاوره ای پیام استفاده می شود:
پاسخ رشته = تأیید (“از کدام حل کننده می خواهید استفاده کنید؟”، “انتخاب حل کننده”، “مستقیم”، “تکرار کننده”);
if (answer.equals (“مستقیم”)) {
  alert (“استفاده از حل کننده مستقیم به حدود 4 گیگابایت حافظه در هنگام حل نیاز دارد.”);
}دیگر {
  alert (“استفاده از حل کننده تکراری به حدود 2 گیگابایت حافظه در هنگام حل نیاز دارد.”);
}
کد مثال
کد زیر زاویه زوم دوربین را تغییر می دهد و گرافیک را برای هر تغییر به روز می کند.
useView(model.view(“view1”)، “/form1/graphics1”);
برای (int i = 0; i < 25; i++) {
  خواب (2000);
  model.view(“view1”).camera().set(“zoomanglefull”, 12-i*5.0/25);
  useGraphics(model.geom(“geom1”)، “/form1/graphics1”);
}
این خط کد گروه نمودار 5 ( pg5 ) را در شیء گرافیکی graphics1 به شکلی با نام دما نمایش می دهد :
useGraphics(model.result(“pg5”)، “/Temperature/graphics1”);
کد زیر مش را در گره درخت مدل mesh1 در شیء گرافیکی graphics1 موجود در کارت پشته کارت نمایش می دهد. خط دوم برای اطمینان از تجسم مناسب مش، دستور بزرگنمایی را اجرا می کند.
useGraphics(model.mesh(“mesh1”)، “/mesh/cardstack1/card1/graphics1”);
zoomExtents(“/mesh/cardstack1/card1/graphics1”);
برای پاک کردن محتویات یک شی گرافیکی از فراخوانی مانند
useGraphics (null، “/form1/graphics1”);
کد زیر یک کادر محاوره ای درخواست را نمایش می دهد که به کاربر اجازه می دهد نام فایل را برای گزارش HTML تایپ کند. اگر کاربر نام فایلی را تایپ کرده باشد، گزارشی ایجاد می شود.
String answerh = درخواست (“نام فایل را وارد کنید”، “نام فایل”، “Untitled.html”);
if (answerh != null) {
  model.result().report(“rpt1”).set(“format”,”html”);
  model.result().report(“rpt1”).set(“نام فایل”,”user:///”+answerh);
  model.result().report(“rpt1”).run();
}
کد زیر مشابه کد بالا است، اما در این مورد گزارش در قالب Microsoft® Word® ذخیره می‌شود ( docx .).
String answerw = request(“نام فایل را وارد کنید”، “نام فایل”، “Untitled.docx”);
if (answerw != null) {
  model.result().report(“rpt2”).set(“format”,”docx”);
  model.result().report(“rpt2”).set(“نام فایل”,”user:///”+answerw);
  model.result().report(“rpt2”).run();
}
این خط کد، نمای شیء گرافیکی form1/graphics1 را به نمای 5 تنظیم می کند ، همانطور که در درخت مدل تعریف شده است:
useView(model.view(“view5”)، “form1/graphics1”);
می‌توانید از دسترسی به داده در ترکیب با ابزار ویرایشگر برای ایجاد یک نوار لغزنده یا یک فیلد ورودی استفاده کنید که سطح شفافیت (آلفا) یک گروه نمودار را تعیین می‌کند. شکل زیر پنجره تنظیمات یک نوار لغزنده را با سطح شفافیت به عنوان منبع نشان می دهد.
در این حالت باید روشی برای به روز رسانی نمای ایجاد کنید که برای کنترل یک رویداد از اسلایدر یا شی فرم فراخوانی می شود. در مثال بالا، نوار لغزنده از یک متد Local استفاده می کند که در قسمت رویدادها تعریف شده است. این روش حاوی یک خط کد است که نمای را به روز می کند:
useView(getView(“/form1/graphics1”)، “/form1/graphics1”);
توجه داشته باشید که سطوح مختلف شفافیت هنگام دسترسی به برنامه از مرورگر با استفاده از سرور COMSOL پشتیبانی نمی‌شوند.
توجه داشته باشید که شما همچنین می توانید یک نمای از دنباله دستور، به عنوان مثال، یک دکمه تنظیم کنید: یک زیرگره view را در زیر گره Views در درخت ویرایشگر انتخاب کنید و روی دکمه Plot زیر درخت کلیک کنید.
برای رفتن به یکی از نماهای استاندارد در پنجره اصلی Graphics، به عنوان مثال در یک افزونه، می توانید از موارد زیر استفاده کنید:
goToView (“xy”);
در یک برنامه به طور مشابه می توانید از یکی از موارد زیر استفاده کنید:
goToView(“xz”، “form1/graphics1”);
goToView(“yz”، app.form(“form1”).formObject(“graphics1”));
برای رفتن به شیء گرافیکی graphics1 به شکل form1 .
این خط کد منبع URL شیء فرم webpage1 را به صفحه وب COMSOL تنظیم می کند:
setWebPageSource(“/form1/webpage1″، “https://www.comsol.com”);
این خط کد یک رشته حاوی عرض و ارتفاع صفحه را تشکیل می دهد:
screenSize = toString(getScreenWidth()) + “-by-” + toString(getScreenHeight());
می توانید رشته را با یک فیلد ورودی یا یک شی نمایش داده با استفاده از این رشته به عنوان منبع ارائه کنید (ابتدا باید اندازه صفحه نمایش رشته اعلام شود).