use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class OnOffSwitch method initialize.
private void initialize() {
iosMode = UIManager.getInstance().isThemeConstant("onOffIOSModeBool", false);
removeAll();
setFocusable(true);
if (iosMode) {
button = null;
switchMaskImage = UIManager.getInstance().getThemeImageConstant("switchMaskImage");
switchOnImage = UIManager.getInstance().getThemeImageConstant("switchOnImage");
switchOffImage = UIManager.getInstance().getThemeImageConstant("switchOffImage");
noTextMode = UIManager.getInstance().isThemeConstant("noTextModeBool", false);
} else {
setLayout(new BoxLayout(BoxLayout.Y_AXIS));
button = new CheckBox(on);
button.setToggle(true);
button.setUIID("Button");
button.setEndsWith3Points(false);
button.getUnselectedStyle().setFont(getUnselectedStyle().getFont());
button.getSelectedStyle().setFont(getSelectedStyle().getFont());
button.getPressedStyle().setFont(getSelectedStyle().getFont());
Dimension d = button.getPreferredSize();
button.setText(off);
int pw = button.getPreferredW();
d.setWidth(Math.max(pw, d.getWidth()));
// prevents the button from growing/shrinking as its states flip
button.setPreferredSize(d);
buttonWidth = button.getPreferredW();
button.setFocusable(false);
updateButton();
addComponent(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
flip();
}
});
}
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class ScaleImageLabel 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.geom.Dimension in project CodenameOne by codenameone.
the class Ads method setHeight.
/**
* {@inheritDoc}
*/
public void setHeight(int height) {
float percent = ((float) height / (float) Display.getInstance().getDisplayHeight());
percent *= 100;
// remove it.
if (percent > 25) {
removeAll();
Label filler = new Label(" ");
filler.setPreferredSize(new Dimension(400, 2));
filler.getStyle().setBgTransparency(0);
addComponent(BorderLayout.CENTER, filler);
revalidate();
} else {
super.setHeight(height);
}
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class InfiniteProgress method calcPreferredSize.
/**
* {@inheritDoc}
*/
protected Dimension calcPreferredSize() {
if (animation == null) {
animation = UIManager.getInstance().getThemeImageConstant("infiniteImage");
if (animation == null) {
int size = Display.getInstance().convertToPixels(7, true);
String f = getUIManager().getThemeConstant("infiniteDefaultColor", null);
int color = 0x777777;
if (f != null) {
color = Integer.parseInt(f, 16);
}
FontImage fi = FontImage.createFixed("" + FontImage.MATERIAL_AUTORENEW, FontImage.getMaterialDesignFont(), color, size, size, 0);
animation = fi.toImage();
}
}
if (animation == null) {
return new Dimension(100, 100);
}
Style s = getStyle();
return new Dimension(s.getHorizontalPadding() + animation.getWidth(), s.getVerticalPadding() + animation.getHeight());
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class ToastBar method updateStatus.
/**
* Updates the ToastBar UI component with the settings of the current status.
*/
private void updateStatus() {
final ToastBarComponent c = getToastBarComponent();
if (c != null) {
try {
if (updatingStatus) {
pendingUpdateStatus = true;
return;
}
updatingStatus = true;
if (c.currentlyShowing != null && !statuses.contains(c.currentlyShowing)) {
c.currentlyShowing = null;
}
if (c.currentlyShowing == null || statuses.isEmpty()) {
if (!statuses.isEmpty()) {
c.currentlyShowing = statuses.get(statuses.size() - 1);
} else {
setVisible(false);
return;
}
}
Status s = c.currentlyShowing;
Label l = new Label(s.getMessage() != null ? s.getMessage() : "");
c.leadButton.getListeners().clear();
c.leadButton.addActionListener(s.getListener());
c.leadButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if (c.currentlyShowing != null && !c.currentlyShowing.showProgressIndicator) {
c.currentlyShowing.clear();
}
ToastBar.this.setVisible(false);
}
});
c.progressLabel.setVisible(s.isShowProgressIndicator());
if (c.progressLabel.isVisible()) {
if (!c.contains(c.progressLabel)) {
c.addComponent(BorderLayout.EAST, c.progressLabel);
}
Image anim = c.progressLabel.getAnimation();
if (anim != null && anim.getWidth() > 0) {
c.progressLabel.setWidth(anim.getWidth());
}
if (anim != null && anim.getHeight() > 0) {
c.progressLabel.setHeight(anim.getHeight());
}
} else {
if (c.contains(c.progressLabel)) {
c.removeComponent(c.progressLabel);
}
}
c.progressBar.setVisible(s.getProgress() >= -1);
if (s.getProgress() >= -1) {
if (!c.contains(c.progressBar)) {
c.addComponent(BorderLayout.SOUTH, c.progressBar);
}
if (s.getProgress() < 0) {
c.progressBar.setInfinite(true);
} else {
c.progressBar.setInfinite(false);
c.progressBar.setProgress(s.getProgress());
}
} else {
c.removeComponent(c.progressBar);
}
c.icon.setVisible(s.getIcon() != null);
if (s.getIcon() != null && c.icon.getIcon() != s.getIcon()) {
c.icon.setIcon(s.getIcon());
}
if (s.getIcon() == null && c.contains(c.icon)) {
c.removeComponent(c.icon);
} else if (s.getIcon() != null && !c.contains(c.icon)) {
c.addComponent(BorderLayout.WEST, c.icon);
}
String oldText = c.label.getText();
if (!oldText.equals(l.getText())) {
if (s.getUiid() != null) {
c.setUIID(s.getUiid());
} else if (defaultUIID != null) {
c.setUIID(defaultUIID);
}
if (c.isVisible()) {
TextArea newLabel = new TextArea();
// newLabel.setColumns(l.getText().length()+1);
// newLabel.setRows(l.getText().length()+1);
newLabel.setFocusable(false);
newLabel.setEditable(false);
// newLabel.getAllStyles().setFgColor(0xffffff);
if (s.getMessageUIID() != null) {
newLabel.setUIID(s.getMessageUIID());
} else if (defaultMessageUIID != null) {
newLabel.setUIID(defaultMessageUIID);
} else {
newLabel.setUIID(c.label.getUIID());
}
if (s.getUiid() != null) {
c.setUIID(s.getUiid());
} else if (defaultUIID != null) {
c.setUIID(defaultUIID);
}
newLabel.setWidth(c.label.getWidth());
newLabel.setText(l.getText());
Dimension oldTextAreaSize = UIManager.getInstance().getLookAndFeel().getTextAreaSize(c.label, true);
Dimension newTexAreaSize = UIManager.getInstance().getLookAndFeel().getTextAreaSize(newLabel, true);
// https://stackoverflow.com/questions/46172993/codename-one-toastbar-nullpointerexception
if (c.label.getParent() != null) {
c.label.getParent().replaceAndWait(c.label, newLabel, CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, true, 300));
c.label = newLabel;
if (oldTextAreaSize.getHeight() != newTexAreaSize.getHeight()) {
c.label.setPreferredH(newTexAreaSize.getHeight());
c.getParent().animateHierarchyAndWait(300);
}
}
} else {
if (s.getMessageUIID() != null) {
c.label.setUIID(s.getMessageUIID());
} else if (defaultMessageUIID != null) {
c.label.setUIID(defaultMessageUIID);
}
if (s.getUiid() != null) {
c.setUIID(s.getUiid());
} else if (defaultUIID != null) {
c.setUIID(defaultUIID);
}
c.label.setText(l.getText());
// c.label.setColumns(l.getText().length()+1);
// c.label.setRows(l.getText().length()+1);
c.label.setPreferredW(c.getWidth());
c.revalidate();
}
} else {
c.revalidate();
}
} finally {
updatingStatus = false;
if (pendingUpdateStatus) {
pendingUpdateStatus = false;
Display.getInstance().callSerially(new Runnable() {
public void run() {
updateStatus();
}
});
}
}
}
}
Aggregations