]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/LabelWidget.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / widget / LabelWidget.java
1 package org.simantics.document.swt.core.widget;
2
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.widgets.Composite;
5 import org.eclipse.swt.widgets.Label;
6 import org.simantics.datatypes.literal.Font;
7 import org.simantics.datatypes.literal.RGB;
8 import org.simantics.document.server.JSONObject;
9 import org.simantics.document.swt.core.SWTDocument;
10 import org.simantics.document.swt.core.SWTDocumentUtils;
11 import org.simantics.document.swt.core.base.LeafWidgetManager;
12
13 public class LabelWidget extends LeafWidgetManager<Label> {
14
15         @Override
16         protected void doUpdateProperties(SWTDocument document, Label control, JSONObject object) {
17
18                 if(control.isDisposed()) return;
19                 
20                 String text = object.getJSONField("text");
21
22                 RGB.Integer background = object.getBeanJSONFieldDefault("background", RGB.Integer.BINDING, new RGB.Integer(255,255,255));
23                 RGB.Integer foreground = object.getBeanJSONFieldDefault("foreground", RGB.Integer.BINDING, new RGB.Integer(0,0,0));
24                 Font font = object.getBeanJSONFieldDefault("font", Font.BINDING, new Font("Arial",10,"Normal"));
25                 String alignment = object.getValue("alignment");
26                 if(alignment == null) alignment = "left";
27                 
28                 control.setText(text);
29                 control.setBackground(document.getColor(background));
30                 control.setForeground(document.getColor(foreground));
31                 control.setFont(document.getFont(font));
32                 
33                 control.setAlignment(SWTDocumentUtils.getAlignment(alignment));
34                 
35         }
36
37         @Override
38         protected Label doCreateControl(SWTDocument document, Composite parent, JSONObject object) {
39                 Label label = new Label(parent, SWT.NONE);
40                 return label;
41         }
42         
43 }