public class UWKit
extends java.lang.Object
Widgets can not be directly constructed because they are interface and more importantly because the actual implementing classes are platform dependent and derive from the underlying UI-toolkit which varies from platform to platform.
This class also defines a number of support methods and types needed in interacting with the widgets.
Modifier and Type | Field and Description |
---|---|
static WidgetFactory |
m_Factory
This needs to be initialized with a platform specific factory object
before any other methods in this class are called.
|
Constructor and Description |
---|
UWKit() |
Modifier and Type | Method and Description |
---|---|
static NumericVariable |
add(Variable variable,
double offset)
this helper method creates a filter object to offset a variables value by
a given amount.
|
static NumericVariable |
add(Variable variable,
Variable offset)
this helper method creates a filter object to offset a variables value by
a given offset.
|
static void |
beep()
generates a 'beep' sound to get the applications users attention.
|
static void |
closeDialog()
This method can used to the currently open dialog.
|
static Variable |
concat(java.lang.Object... args)
creates a proxy object that behaves like a read-only variable that
concatenates two or more strings or variables values converted to
strings.
|
static Variable |
concat(Variable variable1,
Variable variable2)
creates a proxy object that behaves like a read-only variable that
concatenates variables values converted to strings.
|
static NumericVariable |
divide(Variable variable,
double divider)
this helper method creates a filter object to divide a variables value by
a given divider number.
|
static NumericVariable |
divide(Variable variable,
Variable divider)
this helper method creates a filter object to divide a variables value by
a given divider number.
|
static ErrorHandler |
getErrorHandler() |
static NumericVariable |
multiply(Variable variable,
double multiplier)
this helper method creates a filter object to multiply a variables value
by a given multiplier number.
|
static NumericVariable |
multiply(Variable variable,
Variable multiplier)
this helper method creates a filter object to multiple a variables value
by a given multiplier number.
|
static Button |
newButton(java.lang.String text)
constructs a
Button widget. |
static Button |
newButton(java.lang.String look,
java.lang.String text)
This method is identical to
newButton(String) except that this
method constructs a button whose graphics come from two '.png' files. |
static Canvas |
newCanvas(Canvas.OnPaintCallback callback)
this method creates
Canvas widget. |
static CardLayout |
newCardLayout() |
static CheckBox |
newCheckBox(Variable variable,
java.lang.String text)
constructs a
CheckBox widget. |
static CheckBox |
newCheckBox(Variable variable,
java.lang.String text,
java.lang.Object onValue,
java.lang.Object offValue)
constructs a
CheckBox widget. |
static CheckBox |
newCheckBox(Variable variable,
Variable text)
constructs a
CheckBox widget. |
static CheckBox |
newCheckBox(Variable variable,
Variable text,
java.lang.Object onValue,
java.lang.Object offValue)
constructs a
CheckBox widget. |
static ComboBox |
newComboBox(Variable variable,
java.lang.Object... itemsvalues)
constructs a
ComBox widget. |
static ComboBox |
newComboBox(Variable variable,
java.lang.Object[] items,
java.lang.Object[] values)
constructs a
ComBox widget. |
static Label |
newLabel(java.lang.String text)
constructs a
Label widget. |
static Label |
newLabel(Variable text)
constructs a
Label widget. |
static Layout |
newLayout()
constructs a
Layout to hold other layouts or widgets. |
static Layout |
newLayout(boolean border)
constructs a
Layout with optional frame |
static Layout |
newLayout(boolean border,
java.lang.String constraints)
constructs a
Layout with an optional frame and specified
constraints. |
static Layout |
newLayout(boolean border,
java.lang.String title,
java.lang.String constraints) |
static Layout |
newLayout(java.lang.String constraints)
constructs a
Layout to hold other layouts or widgets. |
static OpenGLCanvas |
newOpenGLView()
this method creates
OpenGLCanvas widget. |
static Picture |
newPicture(java.lang.String name)
this method creates
Picture widget. |
static RadioButton |
newRadioButton(Variable variable,
java.lang.String text,
java.lang.Object setValue)
constructs a RadioButton widget.
|
static RadioButton |
newRadioButton(Variable variable,
Variable text,
java.lang.Object setValue)
constructs a RadioButton widget.
|
static Layout |
newScrollLayout()
constructs a
Layout with displays its contents in a scrollable
list. |
static SourceCodeEditor |
newSourceCodeEditor(boolean isNewFile,
java.io.File file)
creates a
SourceCodeEditor widget. |
static SplitLayout |
newSplitLayout(Widget firstLayout,
Widget secondLayout)
constructs a
SplitLayout which combines two layouts to one. |
static TabbedLayout |
newTabbedLayout() |
static TextField |
newTextField(Variable varible,
double fontSize,
int chars)
this method constructs a
TextField widget. |
static TextField |
newTextField(Variable variable,
double fontSize,
int chars,
java.text.Format formatter,
java.text.Format parser)
this method constructs a
TextField widget. |
static TextField |
newTextField(Variable variable,
double fontSize,
int chars,
Variable formatter,
java.text.Format parser)
this method constructs a
TextField widget. |
static Layout |
newTitledLayout(java.lang.String title)
constructs a
Layout with a frame and a title text. |
static Layout |
newTitledLayout(java.lang.String title,
java.lang.String constraints)
constructs a
Layout with a frame and title and specified
constraints. |
static ToggleButton |
newToggleButton(java.lang.String look,
Variable variable,
java.lang.String text,
java.lang.Object setValue)
this method constructs a ToggleButton widget.
|
static ToggleButton |
newToggleButton(java.lang.String look,
Variable variable,
java.lang.String text,
java.lang.Object setValue,
java.lang.Object unsetValue)
this method constructs a ToggleButton widget.
|
static ToggleButton |
newToggleButton(java.lang.String look,
Variable variable,
Variable text,
java.lang.Object setValue,
java.lang.Object unsetValue)
this method constructs a ToggleButton widget.
|
static ToggleButton |
newToggleButton(Variable variable,
java.lang.String text,
java.lang.Object setValue)
this method constructs a ToggleButton widget.
|
static ToggleButton |
newToggleButton(Variable variable,
java.lang.String text,
java.lang.Object setValue,
java.lang.Object unsetValue)
this method constructs a ToggleButton widget.
|
static ToggleButton |
newToggleButton(Variable variable,
Variable text,
java.lang.Object setValue)
this method constructs a ToggleButton widget.
|
static ToggleButton |
newToggleButton(Variable variable,
Variable text,
java.lang.Object setValue,
java.lang.Object unsetValue)
this method constructs a ToggleButton widget.
|
static void |
schedule(int initialDelay,
int period,
java.lang.Runnable task)
this method schedules a code block (wrapped in Runnable) to be executed
in the Event Dispatcher Thread at given intervals.
|
static void |
scheduleInEDT(java.lang.Runnable task)
this method schedules a code block (wrapped in Runnable) to be executed
in the Event Dispatcher Thread.
|
static void |
setDefaultFloatFormat(java.text.Format format)
sets the default
Format object that will be used to
format floating-point values if no other format is specified. |
static void |
setDefaultFormat(java.text.Format format)
sets the default
Format object that will be used to
format format non numeric objects if no other format is specified. |
static void |
setDefaultIntegerFormat(java.text.Format format)
sets the default
Format object that will be used to
format integer values if no other format is specified. |
static void |
setErrorHandler(ErrorHandler errorHandler) |
static void |
setResourceClass(java.lang.Class resourceClass)
sets the class that is used to load resources using the
getResource() method. |
static void |
setResourceLoader(ResourceLoader resourceLoader)
sets the resource loader which all subsequent widget factory methods use
to load resources, such as graphics.
|
static void |
setTranslator(Translator translator)
sets the translator which all subsequent widget factory methods use to
internationalize the widgets.
|
static void |
showConfirmDialog(java.lang.String title,
java.lang.String text,
java.lang.String yes,
java.lang.String no,
java.lang.String cancel,
DialogCallback callback)
puts up or shows a comfirmation dialog
|
static void |
showErrorDialog(java.lang.String title,
java.lang.String text,
java.lang.String yes,
java.lang.String no,
java.lang.String cancel,
DialogCallback callback)
puts up or shows an error dialog
|
static void |
showFileDialog(java.lang.String startDirectory,
boolean newFile,
FileDialogCallback callback)
puts up or shows a file selection dialog.
|
static void |
showInformationDialog(java.lang.String title,
java.lang.String text,
java.lang.String yes,
java.lang.String no,
java.lang.String cancel,
DialogCallback callback)
puts up or shows an information dialog
|
static void |
showWarningDialog(java.lang.String title,
java.lang.String text,
java.lang.String yes,
java.lang.String no,
java.lang.String cancel,
DialogCallback callback)
puts up or shows an warning dialog
|
static NumericVariable |
subtract(Variable variable,
double offset)
this helper method creates a filter object to offset a variables value by
a given offset.
|
static NumericVariable |
subtract(Variable variable,
Variable offset)
this helper method creates a filter object to offset a variables value by
a given offset.
|
static java.lang.String |
translate(java.lang.String string)
translates the given string with the currently set
Translator . |
public static WidgetFactory m_Factory
public static java.lang.String translate(java.lang.String string)
Translator
.string
- the string to translatepublic static void setTranslator(Translator translator)
The internationalization is static i.e. it takes place at the time of constructing a widget, so this needs to be set before any widget are created.
translator
- the translator objectpublic static void setResourceLoader(ResourceLoader resourceLoader)
resourceLoader
- the resource loader objectpublic static void setResourceClass(java.lang.Class resourceClass)
getResource()
method.
Sets the class whose Class.getResource(String)
and
Class.getResourceAsStream(String)
methods are used to
load resource such as graphics.
resourceClass
- the class whose getResource
/
getResourceAsStream
methods are used to load resourcespublic static void setDefaultFloatFormat(java.text.Format format)
Format
object that will be used to
format floating-point values if no other format is specified.format
- the format objectpublic static void setDefaultIntegerFormat(java.text.Format format)
Format
object that will be used to
format integer values if no other format is specified.format
- the format objectpublic static void setDefaultFormat(java.text.Format format)
Format
object that will be used to
format format non numeric objects if no other format is specified.format
- the format objectpublic static void setErrorHandler(ErrorHandler errorHandler)
public static ErrorHandler getErrorHandler()
public static Label newLabel(java.lang.String text)
Label
widget.
A Label
is a simple widget containing more or less static text.
text
- the text for the labelLabel
public static Label newLabel(Variable text)
Label
widget.
This method is identical to newLabel(String)
except that this
method constructs a label whose text comes from a variable allowing the
text of to be changed by changing the value of that variable.
The string for the text is obtained from the value of the variable by
calling the toString()
method on the value object.
text
- the variable that holds the text for this widgetLabel
public static ComboBox newComboBox(Variable variable, java.lang.Object... itemsvalues)
ComBox
widget.
A ComboBox widget is UI component that shows a single value from a list of values and when 'clicked' pops up a menu of all possible values for the user to choose from.
The ComboBox is attached to a Variable
that holds the value
associated with the currently selected menu value.
Note that the values displayed in the UI are different from the 'internal' values used in the code.
The list of possible values consists of pair of objects where the first
object in the pair is used as text in the UI (i.e. in the menu and the
actual combobox) by calling its toString()
method and the second
object is used 'as-is' in the code as the internal value.
For example:
import static com.eazycnc.uwk.UWKit.*;
...
NumericVariable myVar = new NumericVariable(1);
...
ComboBox myComboBox = newComboBox(myVar, "A",1,"B",2,"C",3);
above creates a combobox that displays the texts 'A','B' and 'C' but
internally uses the values 1,2 or 3 in the variable myVar
.variable
- the variable that this ComboBox controls / displaysitemsvalues
- a list of pairs of values for the comboboxComboBox
widgetpublic static ComboBox newComboBox(Variable variable, java.lang.Object[] items, java.lang.Object[] values)
ComBox
widget.
A ComboBox widget is UI component that shows a single value from a list of values and when 'clicked' pops up a menu of all possible values for the user to choose from.
The ComboBox is attached to a Variable
that holds the value
associated with the currently selected menu value.
Note that the values displayed in the UI are different from the 'internal' values used in the code.
The list of possible values to display in the UI and the associated
internal values are given as two arrays of Object
s, the object
for the UI are converted to strings by calling toString
method of
the objects.
For example:
import static com.eazycnc.uwk.UWKit.*;
...
NumericVariable myVar = new NumericVariable(1);
...
String[] UItexts = new String[] {"A", "B", "C"};
Integer[] internalValues = new Integer{1, 2, 3};
ComboBox myComboBox = newComboBox(myVar, UItexts,internalValues);
above creates a combobox that displays the texts 'A','B' and 'C' but
internally uses the values 1,2 or 3 in the variable myVar
.variable
- the variable that this ComboBox controls / displaysitems
- a list objects to be displayed as strings in the comboboxvalues
- a list values associated with the items
ComboBox
widgetpublic static CheckBox newCheckBox(Variable variable, java.lang.String text)
CheckBox
widget.
A check-box is a widget that displays a text along with a box that can be checked/ticked indicating the state of single two state variable.
This method constructs a check-box that is associated with a variable
whose values are of type Boolean
and thus are either true or
false.
variable
- the Variable
the check box is controllingtext
- the label for the check-boxCheckBox
widgetpublic static CheckBox newCheckBox(Variable variable, Variable text)
CheckBox
widget.
This method is identical to newCheckBox(Variable,String)
except
that this method constructs a check-box whose text comes from a variable
allowing the text of to be changed by changing the value of that
variable.
The string for the text is obtained from the value of the variable by
calling the toString()
method on the value object.
variable
- the Variable
the check box is controllingtext
- the Variable
that specifies the label for this
check-boxCheckBox
widgetpublic static CheckBox newCheckBox(Variable variable, java.lang.String text, java.lang.Object onValue, java.lang.Object offValue)
CheckBox
widget.
A check-box is a widget that displays a text along with a box that can be checked/ticked indicating the state of single two state variable.
This method constructs a check-box that is associated with a variable whose two possible values are specified when constructing the widget.
variable
- the Variable
the check box is controllingtext
- the label for the check-boxonValue
- the object that represents the check/ticked stateoffValue
- the object that represents the un-checked/un-ticked stateCheckBox
widgetpublic static CheckBox newCheckBox(Variable variable, Variable text, java.lang.Object onValue, java.lang.Object offValue)
CheckBox
widget.
This method is identical to
newCheckBox(Variable,String,Object,Object)
except that this
method constructs a check-box whose text comes from a variable allowing
the text of to be changed by changing the value of that variable.
The string for the text is obtained from the value of the variable by
calling the toString()
method on the value object.
variable
- the Variable
the check box is controllingtext
- the variable that holds the text for this widgetonValue
- the object that represents the check/ticked stateoffValue
- the object that represents the un-checked/un-ticked stateCheckBox
widgetpublic static RadioButton newRadioButton(Variable variable, java.lang.String text, java.lang.Object setValue)
A RadioButton
is a button that indicates (or not) that one of
more than two possible values have been selected.
This method constructs a RadioButton that displays an 'ON' state if the associated with a variable has the given value.
Typically three or more radio buttons are used as a group to indicate and control the state of a single variable.
variable
- the Variable
this radio button controlstext
- the text to be display in the buttonsetValue
- the value associated with the 'ON' state of this buttonRadioButton
widgetpublic static RadioButton newRadioButton(Variable variable, Variable text, java.lang.Object setValue)
This method is identical to
newRadioButton(Variable,String,Object)
except that this method
constructs a radibutton whose text comes from a variable allowing the
text of to be changed by changing the value of that variable.
The string for the text is obtained from the value of the variable by
calling the toString()
method on the value object.
variable
- the Variable
this radio button controlstext
- the variable that holds text to be display in the buttonsetValue
- the value associated with the 'ON' state of this buttonRadioButton
widgetpublic static ToggleButton newToggleButton(Variable variable, java.lang.String text, java.lang.Object setValue)
A ToggleButton
is functionally identical to either check-box or a
radio button but has a different visual appearance. A toggle-button can
be visually in two states either active/pressed or un-active/un-pressed.
This method construct a toggle-button which is functionally equivalent to a radio button i.e. it shows weather the associated variable is has the given value or not. Clicking an un-active/un-pressed toggle-button will set variable to the associated value but clicking a button in active state will NOT 'un-set' the value.
variable
- the variable this toggle-button controlstext
- the text to be displayed in this buttonsetValue
- the value associated with the active/pressed state of this
buttonToggleButton
widgetpublic static ToggleButton newToggleButton(Variable variable, java.lang.String text, java.lang.Object setValue, java.lang.Object unsetValue)
A ToggleButton
is functionally identical to either check-box or a
radio button but has a different visual appearance. A toggle-button can
be visually in two states either active/pressed or un-active/un-pressed.
This method construct a toggle-button which is functionally equivalent to a check-box i.e. it shows weather the associated variable is has one of two values and clicking the button will toggle the variable value between the two specified values.
variable
- the variable this toggle-button controlstext
- the text to be displayed in this buttonsetValue
- the value associated with the active/pressed state of this
buttonunsetValue
- the value associated with the un-active/un-pressed state of
this buttonToggleButton
widgetpublic static ToggleButton newToggleButton(Variable variable, Variable text, java.lang.Object setValue)
This method is identical to
newToggleButton(Variable,String,Object)
except that this method
constructs a toggle-button whose text comes from a variable allowing the
text of to be changed by changing the value of that variable.
The string for the text is obtained from the value of the variable by
calling the toString()
method on the value object.
variable
- the variable this toggle-button controlstext
- the variable that holds text to be display in the buttonsetValue
- the value associated with the active/pressed state of this
buttonToggleButton
widgetpublic static ToggleButton newToggleButton(Variable variable, Variable text, java.lang.Object setValue, java.lang.Object unsetValue)
This method is identical to
newToggleButton(Variable,String,Object)
except that this method
constructs a toggle-button whose text comes from a variable allowing the
text of to be changed by changing the value of that variable.
The string for the text is obtained from the value of the variable by
calling the toString()
method on the value object.
variable
- the variable this toggle-button controlstext
- the variable that holds text to be display in the buttonsetValue
- the value associated with the active/pressed state of this
buttonunsetValue
- the value associated with the un-active/un-pressed state of
this buttonToggleButton
widgetpublic static ToggleButton newToggleButton(java.lang.String look, Variable variable, java.lang.String text, java.lang.Object setValue)
This method is identical to
newToggleButton(Variable,String,Object)
except that this method
constructs a toggle-button whose graphics come from two '.png' files.
The graphic files need to be named 'look
_selected.png
' and 'look.png
' representing the two
states, active and un-active, of the toggle-button, where 'look
' is the string that is given to this construction method.
The graphics files need to be stored as 'resources' in some package and
the package needs to be identified by specifying a class in the same
package by calling setResourceClass(Class)
prior to
constructing any widgets.
look
- the base name for the graphics filesvariable
- the variable associated with this toggle-buttontext
- the text to be display in the buttonsetValue
- the value associated with the active/pressed state of this
buttonToggleButton
widgetnewButton(String, String)
public static ToggleButton newToggleButton(java.lang.String look, Variable variable, java.lang.String text, java.lang.Object setValue, java.lang.Object unsetValue)
This method is identical to
newToggleButton(Variable,String,Object,Object)
except that this
method constructs a toggle-button whose graphics come from two '.png'
files.
The graphic files need to be named 'look
_selected.png
' and 'look.png
' representing the two
states, active and un-active, of the toggle-button, where 'look
' is the string that is given to this construction method.
The graphics files need to be stored as 'resources' in some package and
the package needs to be identified by specifying a class in the same
package by calling setResourceClass(Class)
prior to
constructing any widgets.
look
- the base name for the graphics filestext
- the text to be display in the buttonvariable
- the variable associated with this toggle-buttonsetValue
- the value associated with the active/pressed state of this
buttonunsetValue
- the value associated with the un-active/un-pressed state of
this buttonToggleButton
widgetnewButton(String, String)
public static ToggleButton newToggleButton(java.lang.String look, Variable variable, Variable text, java.lang.Object setValue, java.lang.Object unsetValue)
This method is identical to
newToggleButton(Variable,Variable,Object,Object)
except that
this method constructs a toggle-button whose graphics come from two
'.png' files.
The graphic files need to be named 'look
_selected.png
' and 'look.png
' representing the two
states, active and un-active, of the toggle-button, where 'look
' is the string that is given to this construction method.
The graphics files need to be stored as 'resources' in some package and
the package needs to be identified by specifying a class in the same
package by calling setResourceClass(Class)
prior to
constructing any widgets.
look
- the base name for the graphics filestext
- the variable that holds the text to be display in the buttonvariable
- the variable associated with this toggle-buttonsetValue
- the value associated with the active/pressed state of this
buttonunsetValue
- the value associated with the un-active/un-pressed state of
this buttonToggleButton
widgetnewButton(String, String)
public static TextField newTextField(Variable varible, double fontSize, int chars)
TextField
widget.
A TextField
is box in the UI that displays the value of a
variable and which the application user can click and enter a new value
for the variable.
Text-fields created with this method use the default formatters for
converting (formatting and parsing) between the internal variable value
and the text representation shown in the field. The formatters
setDefaultFloatFormat(Format)
,
setDefaultIntegerFormat(Format)
and
setDefaultFormat(Format)
are selected based on the variables
value at the instant of creating the widget.
varible
- the variable associated with this text-fieldfontSize
- the font size to use for this text-fieldchars
- approximate number of character space to reserve for this
text-field in the UITextField
widgetpublic static TextField newTextField(Variable variable, double fontSize, int chars, java.text.Format formatter, java.text.Format parser)
TextField
widget.
A TextField
is box in the UI that displays the value of a
variable and which the application user can click and enter a new value
for the variable.
Text-fields created with this method use the specified formatters for converting (formatting and parsing) between the internal variable value and the text representation shown in the field.
variable
- the variable associated with this text-fieldfontSize
- the font size to use for this text-fieldchars
- approximate number of character space to reserve for this
text-field in the UIformatter
- the Format
object used to convert the
variables value to a stringparser
- the Format
object used to convert the
text-fields contents a variable valueTextField
widgetpublic static TextField newTextField(Variable variable, double fontSize, int chars, Variable formatter, java.text.Format parser)
TextField
widget.
A is identical
newTextField(Variable, double, int, Format, Format)
except that
the formatter and parser objects are passed in variables allowing dynamic
changes to the formatting and parsing by changing the value of that
variable.
variable
- the variable associated with this text-fieldfontSize
- the font size to use for this text-fieldchars
- approximate number of character space to reserve for this
text-field in the UIformatter
- the variable that holds the Format
object
used to convert the variables value to a stringparser
- the variable that holds the Format
object
used to convert the text-fields contents a variable valueTextField
widgetpublic static Variable concat(java.lang.Object... args)
Variable
values
(converted to strings) concatenated together.
The returned proxy object is useful for example in passing it as the
variable in newLabel(Variable)
call allowing the construction of
the text of the label by concatenating two strings/variables. Because the
proxy performs the concatenation dynamically changing the value of either
of the variables will then change attached labels text.
The values of variables are converted to Strings by calling their
toString()
methods.
As un-concatenating is not a meaningful concept this proxy does not allow
setValue
operations but throws an
IllegalArgumentException
if that is attempted.
args
- list of Strings or Variables whose values are concatenatedpublic static Variable concat(Variable variable1, Variable variable2)
This method is similar to concat(Object...)
but this takes
explicitly two variables as arguments.
variable1
- first variable whose value converted to string to concatenatevariable2
- second variable whose value converted to string to concatenatepublic static NumericVariable divide(Variable variable, double divider)
The purpose to this method is to create a proxy object that for all practical purposes behaves like a Numeric variable but which does not store the value but instead uses the specified variables value divided by a given divider.
If placed 'between' a TextField
and a NumericVariable
this allows the UI to represent the internal variable value for example
in a different scale or units.
This is one of a group of similar helper methods, see various
multiply(com.eazycnc.uwk.Variable, double)
,multiply(com.eazycnc.uwk.Variable, double)
, add(com.eazycnc.uwk.Variable, double)
and subtract(com.eazycnc.uwk.Variable, double)
methods for companion functions that create similar filters for all basic
arithmetic operations.
Note that it is possible to chain these filters together to create more complex conversions.
variable
- the variable that actually stores the valuedivider
- the dividervariable
divided by
divider
public static NumericVariable divide(Variable variable, Variable divider)
This methods is identical to divide(Variable,double)
expect that
the divider comes from a variable which allows dynamic changing of the
divider by changing that value.
variable
- the variable that actually stores the valuedivider
- the variable that contains the dividervariable
divided by
divider
public static NumericVariable multiply(Variable variable, double multiplier)
The purpose to this method is to create a proxy object that for all practical purposes behaves like a Numeric variable but which does not store the value but instead uses the specified variables value multiplied by a given multiplier.
If placed 'between' a TextField
and a NumericVariable
this allows the UI to represent the internal variable value for example
in a different scale or units.
Here is an example:
NumericVariable myVar = new NumericVariable( 2.0 * Math.PI) // 360 degrees in radians
...
newTextField(multiply(myVar, 180.0/Math.PI ), 16, 8);
In above the variable myVar
holds an angle value in radians, but
in the text-field we want to represent the value as degrees so place a
'multiplier' between variable and the text-field.
This is one of a group of similar helper methods, see various
multiply(com.eazycnc.uwk.Variable, double)
,multiply(com.eazycnc.uwk.Variable, double)
, add(com.eazycnc.uwk.Variable, double)
and subtract(com.eazycnc.uwk.Variable, double)
methods for companion functions that create similar filters for all basic
arithmetic operations.
Note that it is possible to chain these filters together to create more complex conversions.
variable
- the variable that actually stores the valuemultiplier
- the multipliervariable
multiplied
by multiplier
public static NumericVariable multiply(Variable variable, Variable multiplier)
This methods is identical to multiply(Variable,double)
expect
that the multiplier comes from a variable which allows dynamic changing
of the multiplier by changing that value.
variable
- the variable that actually stores the valuemultiplier
- the variable that contains the multipliervariable
multiplied
by multiplier
public static NumericVariable add(Variable variable, double offset)
The purpose to this method is to create a proxy object that for all practical purposes behaves like a Numeric variable but which does not store the value but instead uses the specified variables value offset by a given number.
If placed 'between' a TextField
and a NumericVariable
this allows the UI to represent the internal variable with a different
offset.
This is one of a group of similar helper methods, see various
multiply(com.eazycnc.uwk.Variable, double)
,multiply(com.eazycnc.uwk.Variable, double)
, add(com.eazycnc.uwk.Variable, double)
and subtract(com.eazycnc.uwk.Variable, double)
methods for companion functions that create similar filters for all basic
arithmetic operations.
Note that it is possible to chain these filters together to create more complex conversions.
variable
- the variable that actually stores the valueoffset
- the offsetoffset
public static NumericVariable add(Variable variable, Variable offset)
This methods is identical to add(Variable,double)
expect that
the offset comes from a variable which allows dynamic changing of the
offset by changing that value.
variable
- the variable that actually stores the valueoffset
- the variable that contains the offsetoffset
public static NumericVariable subtract(Variable variable, double offset)
This methods is identical to subtract(Variable,double)
expect
that the offset comes from a variable which allows dynamic changing of
the offset by changing that value.
variable
- the variable that actually stores the valueoffset
- the variable that contains the offsetoffset
public static NumericVariable subtract(Variable variable, Variable offset)
The purpose to this method is to create a proxy object that for all practical purposes behaves like a Numeric variable but which does not store the value but instead uses the specified variables value from which a given offset is subtracted.
If placed 'between' a TextField
and a NumericVariable
this allows the UI to represent the internal variable with a different
offset.
This is one of a group of similar helper methods, see various
multiply(com.eazycnc.uwk.Variable, double)
,multiply(com.eazycnc.uwk.Variable, double)
, add(com.eazycnc.uwk.Variable, double)
and subtract(com.eazycnc.uwk.Variable, double)
methods for companion functions that create similar filters for all basic
arithmetic operations.
Note that it is possible to chain these filters together to create more complex conversions.
variable
- the variable that actually stores the valueoffset
- the offsetoffset
public static SplitLayout newSplitLayout(Widget firstLayout, Widget secondLayout)
SplitLayout
which combines two layouts to one.
A split layout displays two layouts or widgets side by side with a possibly movable divider bar in between.
firstLayout
- the first layout or widgetsecondLayout
- the second layout or widgetSplitLayout
that combines the first and second layouts to onepublic static Layout newLayout()
Layout
to hold other layouts or widgets.
A Layout
is container that holds zero or more other layouts
and/or widgets and lays them out according to constrains.
The actualy laying out of the components in the UI is handled by the wonderful MigLayout. For details of the layout procedure go to www.miglayout.com
Layout
which
uses default constraintspublic static Layout newTitledLayout(java.lang.String title)
Layout
with a frame and a title text.
A titled layout is just like a Layout
but displays a title and a
frame around the widgets it containts.
title
- the title to display with this layoutLayout
which
uses default constraints and displays a frame and titlepublic static Layout newScrollLayout()
Layout
with displays its contents in a scrollable
list.Layout
which
uses default constraints and displays a scroll barpublic static Layout newLayout(java.lang.String constraints)
Layout
to hold other layouts or widgets.
A Layout
is container that holds zero or more other layouts
and/or widgets and lays them out according to specified constrains.
The actualy laying out of the components in the UI is handled by the wonderful MigLayout. For details of the layout procedure go to www.miglayout.com
constraints
- the MigLayout layout constraintsLayout
which
uses default constraintspublic static Layout newLayout(boolean border)
Layout
with optional frameborder
- true if you want a frame displayed around the layoutLayout
which
uses default constraints and optionally displays a framepublic static Layout newTitledLayout(java.lang.String title, java.lang.String constraints)
Layout
with a frame and title and specified
constraints.title
- the title to displayconstraints
- the MigLayout layout constraintsLayout
which
uses default constraints and optionally displays a framenewTitledLayout(String)
public static Layout newLayout(boolean border, java.lang.String constraints)
Layout
with an optional frame and specified
constraints.border
- true if you want a frameconstraints
- the MigLayout layout constraintsLayout
which
uses default constraints and optionally displays a framenewLayout(boolean)
public static TabbedLayout newTabbedLayout()
public static CardLayout newCardLayout()
public static Layout newLayout(boolean border, java.lang.String title, java.lang.String constraints)
public static SourceCodeEditor newSourceCodeEditor(boolean isNewFile, java.io.File file)
SourceCodeEditor
widget.
This create a complete multi-line text editor widget.
isNewFile
- true if this represent a new (non existing) filefile
- the file that contains the textSourceCodeEditor
public static Button newButton(java.lang.String text)
Button
widget.
A button is a UI component that when clicked invokes some action.
See
Button.addActionListener(ActionListener)
and
Button.addButtonListener(com.eazycnc.uwk.widgets.Button.ButtonListener)
for details how to associate actions with buttons.
text
- the text to show on the buttonButton
public static Button newButton(java.lang.String look, java.lang.String text)
newButton(String)
except that this
method constructs a button whose graphics come from two '.png' files.
The graphic files need to be named 'look
_selected.png
' and 'look.png
' representing the two
states, active and un-active, of the toggle-button, where 'look
' is the string that is given to this construction method.
The graphics files need to be stored as 'resources' in some package and
the package needs to be identified by specifying a class in the same
package by calling setResourceClass(Class)
prior to
constructing any widgets.
Following names can be used to access built in graphics:
look
- the base name for the graphics filestext
- the text to show on the buttonButton
public static Picture newPicture(java.lang.String name)
Picture
widget.
A Picture
is a graphics equivalent of a Label
ie it is a
static icon used as decoration or to visually convey some information on
the UI.
The file that contains the graphics need to be stored as 'resources' in
some package and the package needs to be identified by specifying a class
in the same package by calling setResourceClass(Class)
prior
to constructing any widgets.
Only '.png' file format is supported.
Following names can be used to access built in graphics:
name
- full name of the filePicture
public static OpenGLCanvas newOpenGLView()
OpenGLCanvas
widget.
An OpenGL canvas is widget that displays dynamically rendered 3D content.
To render the content you need to implement a
OpenGLCanvas.RenderCallback
.
It also support gesture actions by allowing you to set a gesture handler
which implements
OpenGLCanvas.GestureHandler
.
OpenGLCanvas
public static Canvas newCanvas(Canvas.OnPaintCallback callback)
Canvas
widget.
An OpenGL canvas is widget that displays dynamically rendered 2D content.
To render the content you need to implement a
Canvas.OnPaintCallback
.
callback
- the callback that renders the contentCanvas
public static void schedule(int initialDelay, int period, java.lang.Runnable task)
All code that touches UI elemenst, i.e. widgets, need to be executed in the Event Dispatcher Thread (EDT) so if a background thread or OpenGL rendering thread needs to do that it needs to wrap that code into a Runnable (or Lambda expression) and schedule it using this method.
initialDelay
- delay in milliseconds before the first invocation of the
task
, can be zeroperiod
- time in milliseconds between invocations of the task
task
- the code to be executed wrapped in Runnable
public static void scheduleInEDT(java.lang.Runnable task)
All code that touches UI elemenst, i.e. widgets, need to be executed in the Event Dispatcher Thread (EDT) so if a background thread or OpenGL rendering thread needs to do that it needs to wrap that code into a Runnable (or Lambda expression) and schedule it using this method.
task
- the code to be executed wrapped in Runnable
public static void beep()
public static void showFileDialog(java.lang.String startDirectory, boolean newFile, FileDialogCallback callback)
Dialogs a window like UI elements used to convey or obtain information from the applications user. Dialogs visually interrupt the flow of the application by blocking the user interface.
Because dialogs cannot block the EDT control flow the calls that put up and show dialogs cannot block and wait until the user acts on the dialog, instead a callback needs to be specified that is called when application user finally completes the dialog.
startDirectory
- the initial directory to be display in the file selectornewFile
- true if this should be a 'create new file' dialog, false to
show a 'open existin file' dialogcallback
- the DialogCallback
that is invoked
when the user selects a file or cancels the dialogpublic static void showConfirmDialog(java.lang.String title, java.lang.String text, java.lang.String yes, java.lang.String no, java.lang.String cancel, DialogCallback callback)
A confirmation dialog is a dialog with a given title and displays a question mark, a question and one or more of the 'YES','NO' and 'Cancel' buttons.
Dialogs a window like UI elements used to convey or obtain information from the applications user. Dialogs visually interrupt the flow of the application by blocking the user interface.
Because dialogs cannot block the EDT control flow the calls that put up and show dialogs cannot block and wait until the user acts on the dialog, instead a callback needs to be specified that is called when application user finally completes the dialog.
All dialogs have up to three buttons.
Clicking a button will dismiss the dialog and results in call to the dialog completion call back, which is an instance of ...
The buttons and resulting return values passed to the call back are as follows:
Yes-button |
UWKIt.DialogOptions.Yes |
No-button |
UWKIt.DialogOptions.No |
Cancel-button |
UWKIt.DialogOptions.Cancel |
title
- the title text for the dialogtext
- the actual question in the dialog, can contain some html
formatting tags, at least <b>..</b>
,<i>..</i>
and <br>
are supported.yes
- the text to display in the 'Yes' button, can be null if you
don't want the button to be shownno
- the text to display in the 'No' button, can be null if you
don't want the button to be showncancel
- the text to display in the 'Cancel' button, can be null if you
don't want the button to be showncallback
- the DialogCallback
that is invoked
when the user selects a file or cancels the dialogpublic static void showErrorDialog(java.lang.String title, java.lang.String text, java.lang.String yes, java.lang.String no, java.lang.String cancel, DialogCallback callback)
An error dialog is identical to the confirmation dialog except the icon is appropriate for an error situation.
title
- the title text for the dialogtext
- the actual question in the dialog, can contain some html
formatting tags, at least <b>..</b>
,<i>..</i>
and <br>
are supported.yes
- the text to display in the 'Yes' button, can be null if you
don't want the button to be shownno
- the text to display in the 'No' button, can be null if you
don't want the button to be showncancel
- the text to display in the 'Cancel' button, can be null if you
don't want the button to be showncallback
- the DialogCallback
that is invoked
when the user selects a file or cancels the dialogshowConfirmDialog(String, String, String, String, String,
DialogCallback)
public static void showInformationDialog(java.lang.String title, java.lang.String text, java.lang.String yes, java.lang.String no, java.lang.String cancel, DialogCallback callback)
An information dialog is identical to the confirmation dialog except the icon is appropriate for an the situation.
title
- the title text for the dialogtext
- the actual question in the dialog, can contain some html
formatting tags, at least <b>..</b>
,<i>..</i>
and <br>
are supported.yes
- the text to display in the 'Yes' button, can be null if you
don't want the button to be shownno
- the text to display in the 'No' button, can be null if you
don't want the button to be showncancel
- the text to display in the 'Cancel' button, can be null if you
don't want the button to be showncallback
- the DialogCallback
that is invoked
when the user selects a file or cancels the dialogshowConfirmDialog(String, String, String, String, String,
DialogCallback)
public static void showWarningDialog(java.lang.String title, java.lang.String text, java.lang.String yes, java.lang.String no, java.lang.String cancel, DialogCallback callback)
A warning dialog is identical to the confirmation dialog except the icon is appropriate for an warning situation.
title
- the title text for the dialogtext
- the actual question in the dialog, can contain some html
formatting tags, at least <b>..</b>
,<i>..</i>
and <br>
are supported.yes
- the text to display in the 'Yes' button, can be null if you
don't want the button to be shownno
- the text to display in the 'No' button, can be null if you
don't want the button to be showncancel
- the text to display in the 'Cancel' button, can be null if you
don't want the button to be showncallback
- the DialogCallback
that is invoked
when the user selects a file or cancels the dialogshowConfirmDialog(String, String, String, String, String,
DialogCallback)
public static void closeDialog()
Calling this method will result in the open dialogs
DialogCallback
to be called with the result ==
UWKit.DialogOptions.Cancel
.