use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class ScaleImageButton method calcPreferredSize.
/**
* {@inheritDoc}
*/
@Override
protected Dimension calcPreferredSize() {
Image i = getIcon();
if (i == null) {
return new Dimension();
}
int dw = Display.getInstance().getDisplayWidth();
int iw = i.getWidth();
int ih = i.getHeight();
// a scrollable container the vertical height might be granted providing so much space as to make this unrealistic...
if (iw > dw) {
float ratio = ((float) iw) / ((float) dw);
iw = (int) (((float) iw) / ((float) ratio));
ih = (int) (((float) ih) / ((float) ratio));
}
Style s = getStyle();
return new Dimension(iw + s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL(), ih + s.getPaddingTop() + s.getPaddingBottom());
}
use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class CloudObject method unbindTree.
/**
* Clears the binding to this component tree
* @param ui the container whose children might be bound
*/
public void unbindTree(Container ui) {
int componentCount = ui.getComponentCount();
for (int iter = 0; iter < componentCount; iter++) {
Component c = ui.getComponentAt(iter);
if (c instanceof Container) {
unbindTree((Container) c);
continue;
}
String bind = c.getCloudBoundProperty();
if (bind != null && bind.length() > 0) {
String attributeName = c.getCloudDestinationProperty();
if (attributeName != null) {
unbindProperty(c, bind);
}
}
}
}
use of com.codename1.ui.Container 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.Container in project CodenameOne by codenameone.
the class GameCanvasImplementation method capturePhoto.
public void capturePhoto(ActionListener response) {
captureResponse = response;
final Form current = Display.getInstance().getCurrent();
final Form cam = new Form();
cam.setScrollable(false);
cam.setTransitionInAnimator(CommonTransitions.createEmpty());
cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
cam.setLayout(new BorderLayout());
cam.show();
String platform = System.getProperty("microedition.platform");
MMAPIPlayer p = null;
if (platform != null && platform.indexOf("Nokia") >= 0) {
try {
p = MMAPIPlayer.createPlayer("capture://image", null);
} catch (Throwable e) {
// Ignore all exceptions for image capture, continue with video capture...
}
}
if (p == null) {
try {
p = MMAPIPlayer.createPlayer("capture://video", null);
} catch (Exception e) {
// The Nokia 2630 throws this if image/video capture is not supported
throw new RuntimeException("Image/video capture not supported on this phone");
}
}
final MMAPIPlayer player = p;
MIDPVideoComponent video = new MIDPVideoComponent(player, canvas);
video.play();
video.setVisible(true);
cam.addCommand(new com.codename1.ui.Command("Cancel") {
public void actionPerformed(ActionEvent evt) {
if (player != null) {
player.cleanup();
}
captureResponse.actionPerformed(null);
current.showBack();
}
});
final ActionListener l = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
cam.removeAll();
VideoControl cnt = (VideoControl) player.nativePlayer.getControl("VideoControl");
byte[] pic = cnt.getSnapshot("encoding=jpeg&width=" + current.getWidth() + "&height=" + current.getHeight());
String imagePath = getOutputMediaFile() + ".jpg";
OutputStream out = null;
try {
if (pic != null) {
out = FileSystemStorage.getInstance().openOutputStream(imagePath);
out.write(pic);
}
} catch (Throwable ex) {
ex.printStackTrace();
System.out.println("failed to store picture to " + imagePath);
} finally {
try {
if (out != null) {
out.close();
}
player.cleanup();
} catch (Throwable ex) {
ex.printStackTrace();
}
}
captureResponse.actionPerformed(new ActionEvent(imagePath));
current.showBack();
} catch (Throwable ex) {
ex.printStackTrace();
System.out.println("failed to take picture");
current.showBack();
}
}
};
cam.addGameKeyListener(Display.GAME_FIRE, l);
Container cn = new Container(new BorderLayout()) {
public void pointerReleased(int x, int y) {
l.actionPerformed(null);
}
};
cn.setFocusable(true);
cn.addComponent(BorderLayout.CENTER, video);
cam.addComponent(BorderLayout.CENTER, cn);
cam.revalidate();
// cam.addPointerReleasedListener(l);
}
use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class BarCodeScanner method startScaning.
private void startScaning(ScanResult callback) {
this.callback = callback;
try {
// Add the listener for scan and cancel
Container cmdContainer = new Container(new FlowLayout(Component.CENTER));
Button scanButton = new Button(new Command("Scan") {
public void actionPerformed(ActionEvent evt) {
cameraForm.repaint();
if (snapshotThread != null) {
snapshotThread.continueRun();
}
}
});
Button cancelButton = new Button(new Command("Cancel") {
public void actionPerformed(ActionEvent evt) {
if (snapshotThread != null) {
snapshotThread.stop();
cancelScan();
}
}
});
cmdContainer.addComponent(scanButton);
cmdContainer.addComponent(cancelButton);
cameraForm = new Form();
cameraForm.setScrollable(false);
cameraForm.setLayout(new BorderLayout());
cameraForm.addComponent(BorderLayout.CENTER, media.getVideoComponent());
cameraForm.addComponent(BorderLayout.SOUTH, cmdContainer);
} catch (Exception e) {
// throw new AppException("Image/video capture not supported on this phone", e).setCode(97);
e.printStackTrace();
}
startScan();
}
Aggregations