use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class Oauth2 method showAuthentication.
/**
* This method shows an authentication for login form
*
* @param al a listener that will receive at its source either a token for
* the service or an exception in case of a failure
* @return a component that should be displayed to the user in order to
* perform the authentication
*/
public void showAuthentication(ActionListener al) {
final Form old = Display.getInstance().getCurrent();
InfiniteProgress inf = new InfiniteProgress();
final Dialog progress = inf.showInifiniteBlocking();
Form authenticationForm = new Form("Login");
authenticationForm.setScrollable(false);
if (old != null) {
Command cancel = new Command("Cancel") {
public void actionPerformed(ActionEvent ev) {
if (Display.getInstance().getCurrent() == progress) {
progress.dispose();
}
old.showBack();
}
};
if (authenticationForm.getToolbar() != null) {
authenticationForm.getToolbar().addCommandToLeftBar(cancel);
} else {
authenticationForm.addCommand(cancel);
}
authenticationForm.setBackCommand(cancel);
}
authenticationForm.setLayout(new BorderLayout());
authenticationForm.addComponent(BorderLayout.CENTER, createLoginComponent(al, authenticationForm, old, progress));
}
use of com.codename1.ui.layouts.BorderLayout 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.layouts.BorderLayout in project CodenameOne by codenameone.
the class RSSReader method showRSSEntry.
/**
* Shows a form containing the RSS entry
*
* @param h the parsed entry
*/
protected void showRSSEntry(Hashtable h) {
Form newForm = null;
if (targetContainer != null) {
if (targetContainer instanceof Form) {
newForm = (Form) targetContainer;
} else {
newForm = new Form((String) h.get("title"));
newForm.setLayout(new BorderLayout());
newForm.addComponent(BorderLayout.CENTER, targetContainer);
}
updateComponentValues(newForm, h);
} else {
newForm = new Form((String) h.get("title"));
newForm.setScrollable(false);
WebBrowser c = new WebBrowser();
String s = (String) h.get("description");
s = "<html><body>" + s + "</body></html>";
c.setPage(s, null);
newForm.setLayout(new BorderLayout());
newForm.addComponent(BorderLayout.CENTER, c);
}
if (addBackToTaget) {
final Form sourceForm = Display.getInstance().getCurrent();
Command back = new BackCommand(sourceForm);
newForm.addCommand(back);
newForm.setBackCommand(back);
}
newForm.show();
}
use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class ToastBar method getToastBarComponent.
private ToastBarComponent getToastBarComponent() {
Form f = Display.getInstance().getCurrent();
if (f != null && !(f instanceof Dialog)) {
ToastBarComponent c = (ToastBarComponent) f.getClientProperty("ToastBarComponent");
if (c == null || c.getParent() == null) {
c = new ToastBarComponent();
c.hidden = true;
f.putClientProperty("ToastBarComponent", c);
Container layered = f.getLayeredPane(this.getClass(), true);
layered.setLayout(new BorderLayout());
layered.addComponent(position == Component.TOP ? BorderLayout.NORTH : BorderLayout.SOUTH, c);
updateStatus();
}
if (position == Component.BOTTOM && f.getInvisibleAreaUnderVKB() > 0) {
Style s = c.getAllStyles();
s.setMarginUnit(Style.UNIT_TYPE_PIXELS);
s.setMarginBottom(f.getInvisibleAreaUnderVKB());
}
return c;
}
return null;
}
use of com.codename1.ui.layouts.BorderLayout 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