WebLatte

public class WebLatte

Created by charlie on 7/19/16.

Constructors

WebLatte

public WebLatte()

default constructor

Methods

addButton

public void addButton(String name, int x, int y)

add a button to the window. listen for a click with nextClick()

Parameters:
  • name – the name of the button
  • x – the x coordinate of the upper left corner of the button
  • y – the y coordinate of the upper left corner of the button

addHTML

public void addHTML(String html)

addInput

public void addInput(String name, int x, int y)

draw a text input element into the window

Parameters:
  • name – the name of the text input
  • x – the x coordinate of the upper left corner
  • y – the y coordinate of the upper left corner

clearConsole

public void clearConsole()

clear any printed text in the window

clearElements

public void clearElements()

clear any input elements in the window

clearPaint

public void clearPaint()

clear any drawings in the window

drawCircle

public Element drawCircle(double cx, double cy, double r, ColorLatte color)

Draw a circle into the window will not be visible until you run the paint() function can be cleared with the clearPaint() function

Parameters:
  • cx – the x coordinate of the center of the circle
  • cy – the y coordinate of the center of the circle
  • r – the radius of the circle
  • color – the color of the circle
Returns:

the circle element, which you can modify before you paint.

drawEllipse

public Element drawEllipse(double cx, double cy, double rx, double ry, double rot, ColorLatte color)

Draw an ellipse into the window will not be visible until you run the paint() function can be cleared with the clearPaint() function

Parameters:
  • cx – the x coordinate of the center of the ellipse
  • cy – the y coordinate of the center of the ellipse
  • rx – the radius in the x direction
  • ry – the radius in the y direction
  • rot – the rotation about the center
  • color – the color of the ellipse
Returns:

the ellipse element, which you can modify before you paint.

drawImage

public Element drawImage(String file, double x, double y, double w, double h, double rot)

Draw an image from a local file will not be visible until you run the paint() function can be cleared with the clearPaint() function

Parameters:
  • file – the name of the noun
  • x – the x coordinate of the upper left corner
  • y – the y coordinate of the upper left corner
  • w – the width of the image
  • h – the height of the image
  • rot – the rotation of the image about the center
Returns:

the image element, which you can modify before you paint.

drawLine

public Element drawLine(double x1, double y1, double x2, double y2, double thick, ColorLatte color)

Draw a line into the window will not be visible until you run the paint() function can be cleared with the clearPaint() function

Parameters:
  • x1 – the x coordinate of the starting point
  • y1 – the y coordinate of the starting point
  • x2 – the x coordinate of the ending point
  • y2 – the y coordinate of the ending point
  • thick – the thickness of the line
  • color – the color of the line
Returns:

the line element, which you can modify before you paint.

drawNoun

public Element drawNoun(String name, double x, double y, double w, double h, double rot)

Draw an image from the noun project will not be visible until you run the paint() function can be cleared with the clearPaint() function

Parameters:
  • name – the name of the noun
  • x – the x coordinate of the upper left corner
  • y – the y coordinate of the upper left corner
  • w – the width of the image
  • h – the height of the image
  • rot – the rotation of the image about the center
Returns:

the image element, which you can modify before you paint.

drawRectangle

public Element drawRectangle(double x, double y, double w, double h, double rot, ColorLatte color)

Draw a rectangle into the window. will not be visible until you run the paint() function can be cleared with the clearPaint() function

Parameters:
  • x – the x coordinate of the upper left corner
  • y – the y coordinate of the upper left corner
  • w – the width of the rectangle
  • h – the height of the rectangle
  • rot – rotate the rectangle from its center
  • color – the color of the rectangle
Returns:

the rectangle element, which you can modify before you paint.

drawSVGElement

public Element drawSVGElement(String svg)

draw any svg element, see the svg documentation for html5 (advanced function) will not be visible until you run the paint() function can be cleared with the clearPaint() function

Parameters:
  • svg – a string containing valid svg xml
Returns:

the svg element, which you can modify before you paint.

drawSVGElement

public Element drawSVGElement(Element node)

draw any svg element, see the svg documentation for html5 (advanced function) will not be visible until you run the paint() function can be cleared with the clearPaint() function

Parameters:
  • node – a node containing valid svg representation
Returns:

the svg element, which you can modify before you paint.

drawText

public Element drawText(String s, double x, double y, int size, double rot, ColorLatte color)

Draw some text into the window will not be visible until you run the paint() function can be cleared with the clearPaint() function

Parameters:
  • s – the string to draw
  • x – the x coordinate of the lower left corner
  • y – the y coordinate of the lower left corner
  • size – the height of the text
  • rot – the rotation of the text
  • color – the color of the text
Returns:

the text element, which you can modify before you paint.

getWidth

public int getWidth()
outertype:

WebLatte

the width of the current window

return:the width in pixels

getHeight

public int getHeight()
outertype:

WebLatte

the height of the current window

return:the heigh in pixels

getLeapX

public int getLeapX()

the x coordinate of a pointer on the leap controller

Returns:the coordinate in pixels from the upper left corner

getLeapY

public int getLeapY()

the y coordinate of a pointer on the leap controller

Returns:the coordinate in pixels from the upper left corner

getValue

public String getValue(String name)

gives the value stored in the input element

Parameters:
  • name – the input element’sparkServer name
Returns:

the value typed in this will work with any input element

login

public String login()

open a login modal that requires a login from the user

Returns:the username from a successful user login

makeClickable

public static void makeClickable(Element e)

nextClick

public String nextClick()

Waits for a button to be clicked

Returns:the name of the button that was clicked you can make any element clickable by adding the “clickable” id and giving it a name ex: Element r = drawRectangle(...) r.setAttribute(“class”, “clickable”); r.setAttribute(“name”, “myrectangle”);

nextClick

public String nextClick(long timeout)

Waits for a button to be clicked

Parameters:
  • timeout – if it takes more than this number of millis, return null
Returns:

the name of the button that was clicked

nextLine

public Line nextLine()

wait for the user to input a string

Returns:the user inputted string

paint

public void paint()

paint the drawing to the screen. the program waits a default 25 milliseconds.

paint

public void paint(long timeout)

paint the drawing to the screen.

Parameters:
  • timeout – the program waits for this number of milliseconds.

println

public void println(String s)

print a line to the screen. can include html tags

Parameters:
  • s – the string to print

setTitle

public void setTitle(String title)