Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CodenameOne/src/com/codename1/components/ImageViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
///
/// ```java
/// Form hi = new Form("ImageViewer", new BorderLayout());
/// Image duke = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Label", 3.0f);
/// ImageViewer iv = new ImageViewer(duke);
/// hi.add(BorderLayout.CENTER, iv);
/// hi.show();
/// ```
///
/// You can simulate pinch to zoom on the simulator by dragging the right button away from the top left corner to
Expand Down
6 changes: 6 additions & 0 deletions CodenameOne/src/com/codename1/components/MultiButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
/// a lead component. Up to 4 rows are supported.
///
/// ```java
/// Form hi = new Form("Test MultiButton", BoxLayout.y());
///
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Button", 3.0f);
/// Image emblem = FontImage.createMaterial(FontImage.MATERIAL_ARROW_FORWARD, "Button", 3.0f);
///
/// MultiButton twoLinesNoIcon = new MultiButton("MultiButton");
/// twoLinesNoIcon.setTextLine2("Line 2");
/// MultiButton oneLineIconEmblem = new MultiButton("Icon + Emblem");
Expand Down Expand Up @@ -83,6 +88,7 @@
/// add(twoLinesIconEmblemHorizontal).
/// add(twoLinesIconCheckBox).
/// add(fourLinesIcon);
/// hi.show();
/// ```
///
/// @author Shai Almog
Expand Down
5 changes: 5 additions & 0 deletions CodenameOne/src/com/codename1/components/SpanButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@
/// button has the UIID style of a button.
///
/// ```java
/// Form hi = new Form("Test SpanButton", BoxLayout.y());
///
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Button", 3.0f);
///
/// SpanButton sb = new SpanButton("SpanButton is a composite component (lead component) that looks/acts like a Button but can break lines rather than crop them when the text is very long.");
/// sb.setIcon(icon);
/// hi.add(sb);
/// hi.show();
/// ```
///
/// @author Shai Almog
Expand Down
5 changes: 5 additions & 0 deletions CodenameOne/src/com/codename1/components/SpanLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
/// on a text area combined with a label.
///
/// ```java
/// Form hi = new Form("Test SpanLabel", BoxLayout.y());
///
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Label", 3.0f);
///
/// SpanLabel d = new SpanLabel("Default SpanLabel that can seamlessly line break when the text is really long.");
/// d.setIcon(icon);
/// SpanLabel l = new SpanLabel("NORTH Positioned Icon SpanLabel that can seamlessly line break when the text is really long.");
Expand All @@ -56,6 +60,7 @@
/// c.setIcon(icon);
/// c.setIconPosition(BorderLayout.EAST);
/// hi.add(d).add(l).add(r).add(c);
/// hi.show();
/// ```
///
/// @author Shai Almog
Expand Down
1 change: 1 addition & 0 deletions CodenameOne/src/com/codename1/io/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
///
/// ```java
/// // save a token to storage
/// String myToken = "abc123";
/// Preferences.set("token", myToken);
///
/// // get the token from storage or null if it isn't there
Expand Down
1 change: 1 addition & 0 deletions CodenameOne/src/com/codename1/io/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
///
/// ```java
/// // save a token to storage
/// String myToken = "abc123";
/// Preferences.set("token", myToken);
///
/// // get the token from storage or null if it isn't there
Expand Down
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/system/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
/// combined where the "." elements are replaced by underscores. This class can be implemented in Objective-C
/// (by providing both a header and an "m" file) or in Swift. Objective-C classes follow this convention e.g.:
///
/// ```java
/// ```objc
/// @interface com_my_code_MyNative : NSObject {
/// }
/// - (id)init;
Expand Down
5 changes: 5 additions & 0 deletions CodenameOne/src/com/codename1/ui/ButtonGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
/// the specific `ButtonGroup`.
///
/// ```java
/// Form hi = new Form("Test ButtonGroup", BoxLayout.y());
///
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "CheckBox", 3.0f);
///
/// CheckBox cb1 = new CheckBox("CheckBox No Icon");
/// cb1.setSelected(true);
/// CheckBox cb2 = new CheckBox("CheckBox With Icon", icon);
Expand All @@ -49,6 +53,7 @@
/// new ButtonGroup(rb1, rb2, rb3);
/// rb2.setSelected(true);
/// hi.add(cb1).add(cb2).add(cb3).add(cb4).add(rb1).add(rb2).add(rb3);
/// hi.show();
/// ```
///
/// @author Nir Shabi
Expand Down
5 changes: 5 additions & 0 deletions CodenameOne/src/com/codename1/ui/CheckBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
/// mode using the `com.codename1.ui.Button#setToggle(boolean)` API.
///
/// ```java
/// Form hi = new Form("Test CheckBox", BoxLayout.y());
///
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "CheckBox", 3.0f);
///
/// CheckBox cb1 = new CheckBox("CheckBox No Icon");
/// cb1.setSelected(true);
/// CheckBox cb2 = new CheckBox("CheckBox With Icon", icon);
Expand All @@ -51,6 +55,7 @@
/// new ButtonGroup(rb1, rb2, rb3);
/// rb2.setSelected(true);
/// hi.add(cb1).add(cb2).add(cb3).add(cb4).add(rb1).add(rb2).add(rb3);
/// hi.show();
/// ```
///
/// @author Chen Fishbein
Expand Down
53 changes: 16 additions & 37 deletions CodenameOne/src/com/codename1/ui/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,50 +692,29 @@ public Object getNativeOverlay() {
/// style will be meaningless and will return 0 values. Usage:
///
/// ```java
/// Painter p = new Painter(cmp) {
/// Form hi = new Form("Painter via getAllStyles", new BorderLayout());
/// Container cmp = new Container();
/// cmp.setPreferredSize(new Dimension(300, 300));
/// Painter p = new Painter() {
/// public void paint(Graphics g, Rectangle rect) {
/// boolean antiAliased = g.isAntiAliased();
/// g.setAntiAliased(true);
/// int r = Math.min(rect.getWidth(), rect.getHeight())/2;
/// int x = rect.getX() + rect.getWidth()/2 - r;
/// int y = rect.getY() + rect.getHeight()/2 - r;
/// switch (style) {
/// case CircleButtonStrokedDark:
/// case CircleButtonStrokedLight: {
/// if (cmp.getStyle().getBgTransparency() != 0) {
/// int alpha = cmp.getStyle().getBgTransparency();
/// if (alpha <0) {
/// alpha = 0xff;
/// }
/// g.setColor(cmp.getStyle().getBgColor());
/// g.setAlpha(alpha);
/// g.fillArc(x, y, 2*r-1, 2*r-1, 0, 360);
/// g.setAlpha(0xff);
/// }
/// g.setColor(cmp.getStyle().getFgColor());
/// g.drawArc(x, y, 2*r-1, 2*r-1, 0, 360);
/// break;
/// }
/// case CircleButtonFilledDark:
/// case CircleButtonFilledLight:
/// case CircleButtonTransparentDark:
/// case CircleButtonTransparentLight: {
/// int alpha = cmp.getStyle().getBgTransparency();
/// if (alpha < 0) {
/// alpha = 0xff;
/// }
/// g.setAlpha(alpha);
/// g.setColor(cmp.getStyle().getBgColor());
/// g.fillArc(x, y, 2*r, 2*r, 0, 360);
/// g.setAlpha(0xff);
/// break;
/// }
/// }
///
/// int r = Math.min(rect.getWidth(), rect.getHeight()) / 2;
/// int x = rect.getX() + rect.getWidth() / 2 - r;
/// int y = rect.getY() + rect.getHeight() / 2 - r;
/// g.setColor(cmp.getStyle().getBgColor());
/// g.fillArc(x, y, 2 * r, 2 * r, 0, 360);
/// g.setColor(cmp.getStyle().getFgColor());
/// g.drawArc(x, y, 2 * r - 1, 2 * r - 1, 0, 360);
/// g.setAntiAliased(antiAliased);
/// }
/// };
/// cmp.getAllStyles().setBgColor(0x4488ff);
/// cmp.getAllStyles().setBgTransparency(255);
/// cmp.getAllStyles().setFgColor(0xffffff);
/// cmp.getAllStyles().setBgPainter(p);
/// hi.add(BorderLayout.CENTER, cmp);
/// hi.show();
/// ```
///
/// #### Returns
Expand Down
50 changes: 13 additions & 37 deletions CodenameOne/src/com/codename1/ui/Graphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,50 +644,26 @@ public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int
/// degrees. Usage:
///
/// ```java
/// Painter p = new Painter(cmp) {
/// Form hi = new Form("fillArc / drawArc", new BorderLayout());
/// Container cmp = new Container();
/// cmp.setPreferredSize(new Dimension(300, 300));
/// Painter p = new Painter() {
/// public void paint(Graphics g, Rectangle rect) {
/// boolean antiAliased = g.isAntiAliased();
/// g.setAntiAliased(true);
/// int r = Math.min(rect.getWidth(), rect.getHeight())/2;
/// int x = rect.getX() + rect.getWidth()/2 - r;
/// int y = rect.getY() + rect.getHeight()/2 - r;
/// switch (style) {
/// case CircleButtonStrokedDark:
/// case CircleButtonStrokedLight: {
/// if (cmp.getStyle().getBgTransparency() != 0) {
/// int alpha = cmp.getStyle().getBgTransparency();
/// if (alpha <0) {
/// alpha = 0xff;
/// }
/// g.setColor(cmp.getStyle().getBgColor());
/// g.setAlpha(alpha);
/// g.fillArc(x, y, 2*r-1, 2*r-1, 0, 360);
/// g.setAlpha(0xff);
/// }
/// g.setColor(cmp.getStyle().getFgColor());
/// g.drawArc(x, y, 2*r-1, 2*r-1, 0, 360);
/// break;
/// }
/// case CircleButtonFilledDark:
/// case CircleButtonFilledLight:
/// case CircleButtonTransparentDark:
/// case CircleButtonTransparentLight: {
/// int alpha = cmp.getStyle().getBgTransparency();
/// if (alpha < 0) {
/// alpha = 0xff;
/// }
/// g.setAlpha(alpha);
/// g.setColor(cmp.getStyle().getBgColor());
/// g.fillArc(x, y, 2*r, 2*r, 0, 360);
/// g.setAlpha(0xff);
/// break;
/// }
/// }
///
/// int r = Math.min(rect.getWidth(), rect.getHeight()) / 2;
/// int x = rect.getX() + rect.getWidth() / 2 - r;
/// int y = rect.getY() + rect.getHeight() / 2 - r;
/// g.setColor(0x4488ff);
/// g.fillArc(x, y, 2 * r, 2 * r, 0, 360);
/// g.setColor(0xffffff);
/// g.drawArc(x, y, 2 * r - 1, 2 * r - 1, 0, 360);
/// g.setAntiAliased(antiAliased);
/// }
/// };
/// cmp.getAllStyles().setBgPainter(p);
/// hi.add(BorderLayout.CENTER, cmp);
/// hi.show();
/// ```
///
/// #### Parameters
Expand Down
5 changes: 5 additions & 0 deletions CodenameOne/src/com/codename1/ui/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
/// Label text can be positioned in one of 4 locations as such:
///
/// ```java
/// Form hi = new Form("Test Label", BoxLayout.y());
///
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Label", 3.0f);
///
/// Label left = new Label("Left", icon);
/// left.setTextPosition(Component.LEFT);
/// Label right = new Label("Right", icon);
Expand All @@ -56,6 +60,7 @@
/// Label top = new Label("Top", icon);
/// top.setTextPosition(Component.TOP);
/// hi.add(left).add(right).add(bottom).add(top);
/// hi.show();
/// ```
///
/// @author Chen Fishbein
Expand Down
5 changes: 5 additions & 0 deletions CodenameOne/src/com/codename1/ui/RadioButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
/// mode using the `com.codename1.ui.Button#setToggle(boolean)` API.
///
/// ```java
/// Form hi = new Form("Test RadioButton", BoxLayout.y());
///
/// Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "CheckBox", 3.0f);
///
/// CheckBox cb1 = new CheckBox("CheckBox No Icon");
/// cb1.setSelected(true);
/// CheckBox cb2 = new CheckBox("CheckBox With Icon", icon);
Expand All @@ -51,6 +55,7 @@
/// new ButtonGroup(rb1, rb2, rb3);
/// rb2.setSelected(true);
/// hi.add(cb1).add(cb2).add(cb3).add(cb4).add(rb1).add(rb2).add(rb3);
/// hi.show();
/// ```
///
/// @author Chen Fishbein
Expand Down
5 changes: 5 additions & 0 deletions CodenameOne/src/com/codename1/ui/validation/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
/// [this discussion](https://stackoverflow.com/questions/48481888/codename-one-regexconstraint-to-check-a-valid-phone-number/48483465#48483465) on StackOverflow):
///
/// ```java
/// Form hi = new Form("Phone Validator", BoxLayout.y());
/// TextField phone = new TextField("", "Phone");
/// Validator val = new Validator();
/// val.addConstraint(phone, new Constraint() {
/// public boolean isValid(Object value) {
/// String v = (String)value;
Expand All @@ -78,6 +81,8 @@
/// return "Must be valid phone number";
/// }
/// });
/// hi.add(phone);
/// hi.show();
/// ```
///
/// @author Shai Almog
Expand Down
14 changes: 12 additions & 2 deletions CodenameOne/src/com/codename1/util/MathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,12 @@ public static long floor(double a) {
/// integer that would be returned by the call:
///
/// ```java
/// new Float(f1).compareTo(new Float(f2))
/// float f1 = 1.5f;
/// float f2 = 2.5f;
/// int result = new Float(f1).compareTo(new Float(f2));
/// Form hi = new Form("MathUtil.compare(float)", BoxLayout.y());
/// hi.add(new Label("Float.compareTo result: " + result));
/// hi.show();
/// ```
///
/// #### Parameters
Expand Down Expand Up @@ -1467,7 +1472,12 @@ public static int compare(float f1, float f2) {
/// integer that would be returned by the call:
///
/// ```java
/// new Double(d1).compareTo(new Double(d2))
/// double d1 = 1.5;
/// double d2 = 2.5;
/// int result = new Double(d1).compareTo(new Double(d2));
/// Form hi = new Form("MathUtil.compare(double)", BoxLayout.y());
/// hi.add(new Label("Double.compareTo result: " + result));
/// hi.show();
/// ```
///
/// #### Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ private void bindGlobals(Interpreter interpreter, PlaygroundContext context) thr
interpreter.set("theme", context.getTheme());
interpreter.set("hostForm", context.getHostForm());
interpreter.set("previewRoot", context.getPreviewRoot());
interpreter.set("display", Display.getInstance());
interpreter.set("uiManager", UIManager.getInstance());
interpreter.set("display", resolveDisplayBinding());
interpreter.set("uiManager", resolveUiManagerBinding());
interpreter.set("FontImage", FontImage.class);
interpreter.set("CN", com.codename1.ui.CN.class);
interpreter.set("BoxLayout", BoxLayout.class);
Expand All @@ -179,6 +179,26 @@ private void bindGlobals(Interpreter interpreter, PlaygroundContext context) thr
namespace.importClass("com.codenameone.playground.PlaygroundContext");
}

/// Returns the Display singleton, or the Display class itself when no
/// implementation is bootstrapped (headless snippet validator). The CLI
/// validator only cares about parse/lex errors, so a Class fallback is
/// enough -- the script never actually runs against the binding.
private Object resolveDisplayBinding() {
try {
return Display.getInstance();
} catch (Throwable ex) {
return Display.class;
}
}

private Object resolveUiManagerBinding() {
try {
return UIManager.getInstance();
} catch (Throwable ex) {
return UIManager.class;
}
}

private ScriptPlan adaptScript(String script) {
String adapted = unwrapSingleTopLevelClass(script);
String normalized = adapted == null ? script : adapted;
Expand Down
Loading
Loading