Skip to content

Commit

Permalink
example of custom widget
Browse files Browse the repository at this point in the history
  • Loading branch information
mcicolella committed Aug 12, 2017
1 parent e479fce commit f7a1e58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Expand Up @@ -77,9 +77,12 @@ public void renderSingleObject(EnvObjectLogic obj) {
if ((obj.getPojo().getCurrentRepresentation().getIcon() != null)
&& !obj.getPojo().getCurrentRepresentation().getIcon().equalsIgnoreCase("")) {
try {
//WidgetTest widget = new WidgetTest(obj);
//paintImage(widget.draw());
paintImage(obj.getPojo());
// if (obj.getPojo().getSimpleType().equalsIgnoreCase("thermometer")) {
WidgetTest widget = new WidgetTest(obj);
paintImage(widget.draw());
// } else {
// paintImage(obj.getPojo());
// }
} catch (RuntimeException e) {
drawPlainObject(obj);
} finally {
Expand Down
Expand Up @@ -23,6 +23,7 @@
import com.freedomotic.core.ResourcesManager;
import com.freedomotic.things.EnvObjectLogic;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

Expand Down Expand Up @@ -54,8 +55,13 @@ public synchronized BufferedImage draw() {
String name = obj.getPojo().getCurrentRepresentation().getIcon();
BufferedImage resource = ResourcesManager.getResource(name);
Graphics2D canvas = resource.createGraphics();
canvas.setColor(Color.red);
canvas.fillRect(0, 0, (int) 10, (int) resource.getHeight());
if (obj.getPojo().getSimpleType().equalsIgnoreCase("thermometer")) {
canvas.setColor(Color.RED);
canvas.fillRect(0, 0, (int) 64, (int) resource.getHeight());
canvas.setFont(new Font("Arial", Font.BOLD, 20));
canvas.setColor(Color.BLACK);
canvas.drawString(obj.getBehavior("temperature").getValueAsString(), 5, 40);
}
return resource;
} catch (Exception e) {
Freedomotic.getStackTraceInfo(e);
Expand Down

0 comments on commit f7a1e58

Please sign in to comment.