use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.
the class RSSReader method createRendererContainer.
private Container createRendererContainer() {
Container entries = new Container(new BoxLayout(BoxLayout.Y_AXIS));
entries.setUIID("RSSEntry");
Label title = new Label();
title.setName("title");
title.setUIID("RSSTitle");
entries.addComponent(title);
TextArea description = new TextArea(2, 30);
description.setGrowByContent(false);
description.setName("details");
description.setUIID("RSSDescription");
description.setScrollVisible(false);
entries.addComponent(description);
if (iconPlaceholder != null) {
Container wrap = new Container(new BorderLayout());
wrap.addComponent(BorderLayout.CENTER, entries);
Label icon = new Label();
icon.setIcon(iconPlaceholder);
icon.setUIID("RSSIcon");
icon.setName("icon");
wrap.addComponent(BorderLayout.WEST, icon);
entries = wrap;
}
return entries;
}
use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.
the class RSSReader method updateComponentValues.
void updateComponentValues(Container root, Hashtable h) {
int c = root.getComponentCount();
for (int iter = 0; iter < c; iter++) {
Component current = root.getComponentAt(iter);
// subclasses
if (current.getClass() == com.codename1.ui.Container.class || current.getClass() == com.codename1.ui.Tabs.class) {
updateComponentValues((Container) current, h);
continue;
}
String n = current.getName();
if (n != null) {
String val = (String) h.get(n);
if (val != null) {
if (current instanceof Button) {
final String url = (String) val;
((Button) current).addActionListener(new Listener(url));
continue;
}
if (current instanceof Label) {
((Label) current).setText(val);
continue;
}
if (current instanceof TextArea) {
((TextArea) current).setText(val);
continue;
}
if (current instanceof WebBrowser) {
((WebBrowser) current).setPage(val, null);
continue;
}
}
}
}
}
use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.
the class AbstractChart method drawLabel.
/**
* Draws a text label.
*
* @param canvas the canvas
* @param labelText the label text
* @param renderer the renderer
* @param prevLabelsBounds the previous rendered label bounds
* @param centerX the round chart center on X axis
* @param centerY the round chart center on Y axis
* @param shortRadius the short radius for the round chart
* @param longRadius the long radius for the round chart
* @param currentAngle the current angle
* @param angle the label extra angle
* @param left the left side
* @param right the right side
* @param color the label color
* @param paint the paint
* @param line if a line to the label should be drawn
* @param display display the label anyway
*/
protected void drawLabel(Canvas canvas, String labelText, DefaultRenderer renderer, List<Rectangle2D> prevLabelsBounds, int centerX, int centerY, float shortRadius, float longRadius, float currentAngle, float angle, int left, int right, int color, Paint paint, boolean line, boolean display) {
if (renderer.isShowLabels() || display) {
paint.setColor(color);
double rAngle = Math.toRadians(90 - (currentAngle + angle / 2));
double sinValue = Math.sin(rAngle);
double cosValue = Math.cos(rAngle);
int x1 = Math.round(centerX + (float) (shortRadius * sinValue));
int y1 = Math.round(centerY + (float) (shortRadius * cosValue));
int x2 = Math.round(centerX + (float) (longRadius * sinValue));
int y2 = Math.round(centerY + (float) (longRadius * cosValue));
float size = renderer.getLabelsTextSize();
float extra = Math.max(size / 2, 10);
paint.setTextAlign(Component.LEFT);
if (x1 > x2) {
extra = -extra;
paint.setTextAlign(Component.RIGHT);
}
float xLabel = x2 + extra;
float yLabel = y2;
float width = right - xLabel;
if (x1 > x2) {
width = xLabel - left;
}
labelText = getFitText(labelText, width, paint);
float widthLabel = paint.measureText(labelText);
boolean okBounds = false;
while (!okBounds && line) {
boolean intersects = false;
int length = prevLabelsBounds.size();
for (int j = 0; j < length && !intersects; j++) {
Rectangle2D prevLabelBounds = prevLabelsBounds.get(j);
if (prevLabelBounds.intersects(xLabel, yLabel, widthLabel, size)) {
intersects = true;
yLabel = (float) Math.max(yLabel, prevLabelBounds.getY() + prevLabelBounds.getHeight());
}
}
okBounds = !intersects;
}
if (line) {
y2 = (int) (yLabel - size / 2);
canvas.drawLine(x1, y1, x2, y2, paint);
canvas.drawLine(x2, y2, x2 + extra, y2, paint);
} else {
paint.setTextAlign(Component.CENTER);
}
canvas.drawText(labelText, xLabel, yLabel, paint);
if (line) {
prevLabelsBounds.add(PkgUtils.makeRect(xLabel, yLabel, xLabel + widthLabel, yLabel + size));
}
}
}
use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.
the class GlassTutorial method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g, Rectangle rect) {
if (internal == null) {
internal = new Label(" ");
internal.setUIID("GlassTutorial");
}
internal.setSize(rect.getSize());
internal.paintComponent(g);
int componentCount = vec.size();
for (int iter = 0; iter < componentCount; iter++) {
Component current = (Component) vec.elementAt(iter);
String pos = (String) current.getClientProperty(POS);
Component dest = (Component) current.getClientProperty(DEST);
int xpos = dest.getAbsoluteX();
int ypos = dest.getAbsoluteY();
int w = dest.getWidth();
int h = dest.getHeight();
if (pos.equals(BorderLayout.CENTER)) {
current.setX(xpos);
current.setY(ypos);
current.setWidth(w);
current.setHeight(h);
current.paintComponent(g);
continue;
}
Dimension d = current.getPreferredSize();
current.setWidth(d.getWidth());
current.setHeight(d.getHeight());
if (pos.equals(BorderLayout.SOUTH)) {
current.setX(xpos + w / 2 - d.getWidth() / 2);
current.setY(ypos + h);
current.paintComponent(g);
continue;
}
if (pos.equals(BorderLayout.NORTH)) {
current.setX(xpos + w / 2 - d.getWidth() / 2);
current.setY(ypos - d.getHeight());
current.paintComponent(g);
continue;
}
if (pos.equals(BorderLayout.EAST)) {
current.setX(xpos + w);
current.setY(ypos + h / 2 - d.getHeight() / 2);
current.paintComponent(g);
continue;
}
if (pos.equals(BorderLayout.WEST)) {
current.setX(xpos - d.getWidth());
current.setY(ypos + h / 2 - d.getHeight() / 2);
current.paintComponent(g);
continue;
}
}
}
use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.
the class LazyValueC method postCreateComponents.
/**
* Invoked after the components were created to allow properties that require the entire
* tree to exist to update the component. This is useful for properties that point
* at other components.
*/
private void postCreateComponents(DataInputStream in, Container parent, Resources res) throws Exception {
// finds the component whose properties need to update
String name = in.readUTF();
Component lastComponent = null;
while (name.length() > 0) {
if (lastComponent == null || !lastComponent.getName().equals(name)) {
lastComponent = findByName(name, parent);
}
Component c = lastComponent;
int property = in.readInt();
modifyingProperty(c, property);
switch(property) {
case PROPERTY_COMMAND_LEGACY:
{
readCommand(in, c, parent, res, true);
break;
}
case PROPERTY_COMMAND:
{
readCommand(in, c, parent, res, false);
break;
}
case PROPERTY_LABEL_FOR:
c.setLabelForComponent((Label) findByName(in.readUTF(), parent));
break;
case PROPERTY_LEAD_COMPONENT:
((Container) c).setLeadComponent(findByName(in.readUTF(), parent));
break;
case PROPERTY_NEXT_FOCUS_UP:
c.setNextFocusUp(findByName(in.readUTF(), parent));
break;
case PROPERTY_NEXT_FOCUS_DOWN:
c.setNextFocusDown(findByName(in.readUTF(), parent));
break;
case PROPERTY_NEXT_FOCUS_LEFT:
c.setNextFocusLeft(findByName(in.readUTF(), parent));
break;
case PROPERTY_NEXT_FOCUS_RIGHT:
c.setNextFocusRight(findByName(in.readUTF(), parent));
break;
}
name = in.readUTF();
}
}
Aggregations