use of com.codename1.ui.Form in project CodenameOne by codenameone.
the class OnOffSwitch method animateTo.
private void animateTo(final boolean value, final int position) {
int switchButtonPadInt = UIManager.getInstance().getThemeConstant("switchButtonPadInt", 16);
if (Display.getInstance().getDisplayWidth() > 480) {
// is retina
switchButtonPadInt *= 2;
}
final Motion current = Motion.createEaseInOutMotion(Math.abs(position), switchMaskImage.getWidth() - 2 * switchButtonPadInt, 100);
current.start();
deltaX = position;
getComponentForm().registerAnimated(new Animation() {
public boolean animate() {
deltaX = current.getValue();
if (value) {
deltaX *= -1;
}
dragged = true;
if (current.isFinished()) {
dragged = false;
Form f = getComponentForm();
if (f != null) {
f.deregisterAnimated(this);
}
OnOffSwitch.this.setValue(value);
}
repaint();
return false;
}
public void paint(Graphics g) {
}
});
dragged = true;
}
use of com.codename1.ui.Form 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.Form 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.Form in project CodenameOne by codenameone.
the class ToastBar method setVisible.
/**
* Shows or hides the {@code ToastBar}.
* @param visible
*/
public void setVisible(boolean visible) {
final ToastBarComponent c = getToastBarComponent();
if (c == null || c.isVisible() == visible) {
return;
}
if (visible) {
c.hidden = true;
c.setVisible(false);
c.setHeight(0);
c.setShouldCalcPreferredSize(true);
c.getParent().revalidate();
c.hidden = false;
c.label.setPreferredH(UIManager.getInstance().getLookAndFeel().getTextAreaSize(c.label, true).getHeight());
c.setShouldCalcPreferredSize(true);
$(c).slideUpAndWait(2);
$(c).slideDownAndWait(800);
c.setVisible(true);
updateStatus();
} else {
Form f = c.getComponentForm();
if (Display.getInstance().getCurrent() == f && !f.getMenuBar().isMenuShowing()) {
if (this.position == Component.BOTTOM) {
c.setY(c.getY() + c.getHeight());
}
$(c).slideUpAndWait(500);
} else {
c.getParent().revalidate();
}
c.hidden = true;
c.setVisible(false);
}
}
use of com.codename1.ui.Form in project CodenameOne by codenameone.
the class TestRecorder method generatePointerEventArguments.
private String generatePointerEventArguments(int x, int y) {
com.codename1.ui.Component cmp = getCodenameOneComponentAt(x, y);
if (cmp.getParent() instanceof Form) {
cmp = cmp.getParent();
}
String componentName = cmp.getName();
if (componentName == null) {
componentName = getPathToComponent(cmp);
} else {
componentName = "\"" + componentName + "\"";
}
float actualX = ((float) x - cmp.getAbsoluteX()) / ((float) cmp.getWidth());
float actualY = ((float) y - cmp.getAbsoluteY()) / ((float) cmp.getHeight());
return "(" + actualX + "f, " + actualY + "f, " + componentName + ");\n";
}
Aggregations