use of com.codename1.ui.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.ui.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.ui.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.ui.Label in project CodenameOne by codenameone.
the class JavaSEPort method downloadSkin.
private File downloadSkin(File skinDir, String url, String version, JLabel label) throws IOException {
String fileName = url.substring(url.lastIndexOf("/"));
File skin = new File(skinDir.getAbsolutePath() + "/" + fileName);
HttpURLConnection.setFollowRedirects(true);
URL u = new URL(url);
FileOutputStream os = new FileOutputStream(skin);
URLConnection uc = u.openConnection();
InputStream is = uc.getInputStream();
int length = uc.getContentLength();
byte[] buffer = new byte[65536];
int size = is.read(buffer);
int offset = 0;
int percent = 0;
String msg = label.getText();
if (length > 0) {
System.out.println("Downloading " + length + " bytes");
}
while (size > -1) {
offset += size;
if (length > 0) {
float f = ((float) offset) / ((float) length) * 100;
if (percent != ((int) f)) {
percent = (int) f;
label.setText(msg + " " + percent + "%");
label.repaint();
}
} else {
if (percent < offset / 102400) {
percent = offset / 102400;
System.out.println("Downloaded " + percent + "00Kb");
}
}
os.write(buffer, 0, size);
size = is.read(buffer);
}
is.close();
os.close();
// store the skin version
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.put(fileName, version);
return skin;
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class GameCanvasImplementation method captureAudio.
public void captureAudio(ActionListener response) {
captureResponse = response;
try {
final Form current = Display.getInstance().getCurrent();
final MMAPIPlayer player = MMAPIPlayer.createPlayer("capture://audio", null);
RecordControl record = (RecordControl) player.nativePlayer.getControl("RecordControl");
if (record == null) {
player.cleanup();
throw new RuntimeException("Capture Audio is not supported on this device");
}
final Form cam = new Form();
cam.setTransitionInAnimator(CommonTransitions.createEmpty());
cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
cam.setLayout(new BorderLayout());
cam.show();
player.play();
final Label time = new Label("0:00");
cam.addComponent(BorderLayout.SOUTH, time);
cam.revalidate();
ActionListener l = new ActionListener() {
boolean recording = false;
OutputStream out = null;
String audioPath = null;
RecordControl record;
public void actionPerformed(ActionEvent evt) {
if (!recording) {
record = (RecordControl) player.nativePlayer.getControl("RecordControl");
recording = true;
String type = record.getContentType();
String prefix = "";
if (type.endsWith("wav")) {
prefix = ".wav";
} else if (type.endsWith("amr")) {
prefix = ".amr";
} else if (type.endsWith("3gpp")) {
prefix = ".3gp";
}
audioPath = getOutputMediaFile() + prefix;
try {
out = FileSystemStorage.getInstance().openOutputStream(audioPath);
record.setRecordStream(out);
record.startRecord();
cam.registerAnimated(new Animation() {
long current = System.currentTimeMillis();
long zero = current;
int sec = 0;
public boolean animate() {
long now = System.currentTimeMillis();
if (now - current > 1000) {
current = now;
sec++;
return true;
}
return false;
}
public void paint(Graphics g) {
String txt = sec / 60 + ":" + sec % 60;
time.setText(txt);
}
});
} catch (IOException ex) {
ex.printStackTrace();
System.out.println("failed to store audio to " + audioPath);
} finally {
}
} else {
if (out != null) {
try {
record.stopRecord();
record.commit();
out.close();
player.cleanup();
} catch (Exception ex) {
ex.printStackTrace();
}
}
captureResponse.actionPerformed(new ActionEvent(audioPath));
current.showBack();
}
}
};
cam.addGameKeyListener(Display.GAME_FIRE, l);
cam.addPointerReleasedListener(l);
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException("failed to start camera");
}
}
Aggregations