use of com.codename1.ui.Image in project CodenameOne by codenameone.
the class ImageViewer method setImage.
/**
* Sets the currently showing image
* @param image the image to set
*/
public void setImage(Image image) {
if (this.image != image) {
panPositionX = 0.5f;
panPositionY = 0.5f;
zoom = MIN_ZOOM;
this.image = image;
updatePositions();
repaint();
if (image.isAnimation()) {
Form f = getComponentForm();
if (f != null) {
f.registerAnimated(this);
}
}
}
}
use of com.codename1.ui.Image in project CodenameOne by codenameone.
the class ImageViewer method paint.
/**
* {@inheritDoc}
*/
@Override
public void paint(Graphics g) {
if (panPositionX < 0) {
Style s = getStyle();
int width = getWidth() - s.getHorizontalPadding();
float ratio = ((float) width) * (panPositionX * -1);
g.drawImage(image, ((int) ratio) + getX() + imageX, getY() + imageY, imageDrawWidth, imageDrawHeight);
if (cycleLeft || swipeableImages.getSelectedIndex() > getImageLeftPos()) {
Image left = getImageLeft();
if (swipePlaceholder != null) {
left.asyncLock(swipePlaceholder);
} else {
left.lock();
}
ratio = ratio - width;
imageAspectCalc(left);
g.drawImage(left, ((int) ratio) + getX() + prefX, getY() + prefY, prefW, prefH);
}
return;
}
if (panPositionX > 1) {
Style s = getStyle();
int width = getWidth() - s.getHorizontalPadding();
float ratio = ((float) width) * (1 - panPositionX);
g.drawImage(image, ((int) ratio) + getX() + imageX, getY() + imageY, imageDrawWidth, imageDrawHeight);
if (cycleRight || swipeableImages.getSelectedIndex() < getImageRightPos()) {
Image right = getImageRight();
if (swipePlaceholder != null) {
right.asyncLock(swipePlaceholder);
} else {
right.lock();
}
ratio = ratio + width;
imageAspectCalc(right);
g.drawImage(right, ((int) ratio) + getX() + prefX, getY() + prefY, prefW, prefH);
}
return;
}
// can happen in the GUI builder
if (image != null) {
g.drawImage(image, getX() + imageX, getY() + imageY, imageDrawWidth, imageDrawHeight);
}
}
use of com.codename1.ui.Image in project CodenameOne by codenameone.
the class InfiniteProgress method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g) {
if (this.getComponentForm() != null && Display.getInstance().getCurrent() != this.getComponentForm()) {
return;
}
super.paint(g);
if (animation == null) {
return;
}
int v = angle % 360;
Style s = getStyle();
/*if(g.isAffineSupported()) {
g.rotate(((float)v) / 57.2957795f, getAbsoluteX() + s.getPadding(LEFT) + getWidth() / 2, getAbsoluteY() + s.getPadding(TOP) + getHeight() / 2);
g.drawImage(getAnimation(), getX() + s.getPadding(LEFT), getY() + s.getPadding(TOP));
g.resetAffine();
} else {*/
Image rotated;
if (animation instanceof FontImage) {
rotated = animation.rotate(v);
} else {
Integer angle = new Integer(v);
rotated = cache.get(angle);
if (rotated == null) {
rotated = animation.rotate(v);
cache.put(v, rotated);
}
}
g.drawImage(rotated, getX() + s.getPaddingLeftNoRTL(), getY() + s.getPaddingTop());
// }
}
use of com.codename1.ui.Image in project CodenameOne by codenameone.
the class InteractionDialog method showPopupDialog.
/**
* A popup dialog is shown with the context of a component and its selection, it is disposed seamlessly if the back button is pressed
* or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
* dialog has the PopupDialog style by default.
*
* @param rect the screen rectangle to which the popup should point
*/
public void showPopupDialog(Rectangle rect) {
disposed = false;
if (getUIID().equals("Dialog")) {
setUIID("PopupDialog");
if (getTitleComponent().getUIID().equals("DialogTitle")) {
getTitleComponent().setUIID("PopupDialogTitle");
}
getContentPane().setUIID("PopupContentPane");
}
Component contentPane = getContentPane();
Label title = getTitleComponent();
UIManager manager = getUIManager();
String dialogTitle = title.getText();
// preferred size logic of the dialog won't work with large title borders
if ((dialogTitle != null || dialogTitle.length() == 0) && manager.isThemeConstant("hideEmptyTitleBool", false)) {
boolean b = getTitle().length() > 0;
titleArea.setVisible(b);
getTitleComponent().setVisible(b);
if (!b && manager.isThemeConstant("shrinkPopupTitleBool", true)) {
getTitleComponent().setPreferredSize(new Dimension(0, 0));
getTitleComponent().getStyle().setBorder(null);
titleArea.setPreferredSize(new Dimension(0, 0));
if (getContentPane().getClientProperty("$ENLARGED_POP") == null) {
getContentPane().putClientProperty("$ENLARGED_POP", Boolean.TRUE);
int cpPaddingTop = getContentPane().getStyle().getPaddingTop();
int titlePT = getTitleComponent().getStyle().getPaddingTop();
byte[] pu = getContentPane().getStyle().getPaddingUnit();
if (pu == null) {
pu = new byte[4];
}
pu[0] = Style.UNIT_TYPE_PIXELS;
getContentPane().getStyle().setPaddingUnit(pu);
int pop = Display.getInstance().convertToPixels(manager.getThemeConstant("popupNoTitleAddPaddingInt", 1), false);
getContentPane().getStyle().setPadding(TOP, pop + cpPaddingTop + titlePT);
}
}
}
// allows a text area to recalculate its preferred size if embedded within a dialog
revalidate();
Style contentPaneStyle = getStyle();
boolean restoreArrow = false;
if (manager.isThemeConstant(getUIID() + "ArrowBool", false)) {
Image t = manager.getThemeImageConstant(getUIID() + "ArrowTopImage");
Image b = manager.getThemeImageConstant(getUIID() + "ArrowBottomImage");
Image l = manager.getThemeImageConstant(getUIID() + "ArrowLeftImage");
Image r = manager.getThemeImageConstant(getUIID() + "ArrowRightImage");
Border border = contentPaneStyle.getBorder();
if (border != null) {
border.setImageBorderSpecialTile(t, b, l, r, rect);
restoreArrow = true;
}
}
calcPreferredSize();
int prefHeight = getPreferredH();
int prefWidth = getPreferredW();
if (contentPaneStyle.getBorder() != null) {
prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
}
Form f = Display.getInstance().getCurrent();
int availableHeight = getLayeredPane(f).getParent().getHeight();
int availableWidth = getLayeredPane(f).getParent().getWidth();
int width = Math.min(availableWidth, prefWidth);
int x = 0;
int y = 0;
boolean showPortrait = Display.getInstance().isPortrait();
// if we don't have enough space then disregard device orientation
if (showPortrait) {
if (availableHeight < (availableWidth - rect.getWidth()) / 2) {
showPortrait = false;
}
} else {
if (availableHeight / 2 > availableWidth - rect.getWidth()) {
showPortrait = true;
}
}
if (showPortrait) {
if (width < availableWidth) {
int idealX = rect.getX() - width / 2 + rect.getSize().getWidth() / 2;
// if the ideal position is less than 0 just use 0
if (idealX > 0) {
// if the idealX is too far to the right just align to the right
if (idealX + width > availableWidth) {
x = availableWidth - width;
} else {
x = idealX;
}
}
}
if (rect.getY() < availableHeight / 2) {
// popup downwards
y = rect.getY();
int height = Math.min(prefHeight, availableHeight - y);
show(y, Math.max(0, availableHeight - height - y), x, Math.max(0, availableWidth - width - x));
} else {
// popup upwards
int height = Math.min(prefHeight, rect.getY() - getLayeredPane(f).getAbsoluteY());
y = rect.getY() - height - getLayeredPane(f).getAbsoluteY();
show(y, Math.max(0, getLayeredPane(f).getComponentForm().getHeight() - rect.getY()), x, Math.max(0, availableWidth - width - x));
}
} else {
int height = Math.min(prefHeight, availableHeight);
if (height < availableHeight) {
int idealY = rect.getY() - height / 2 + rect.getSize().getHeight() / 2;
// if the ideal position is less than 0 just use 0
if (idealY > 0) {
// if the idealY is too far up just align to the top
if (idealY + height > availableHeight) {
y = availableHeight - height;
} else {
y = idealY;
}
}
}
if (prefWidth > rect.getX()) {
// popup right
x = rect.getX() + rect.getSize().getWidth();
if (x + prefWidth > availableWidth) {
x = availableWidth - prefWidth;
}
width = Math.min(prefWidth, availableWidth - x);
show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
} else {
// popup left
width = Math.min(prefWidth, availableWidth - (availableWidth - rect.getX()));
x = rect.getX() - width;
show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
}
}
/*if(restoreArrow) {
contentPaneStyle.getBorder().clearImageBorderSpecialTile();
}*/
}
use of com.codename1.ui.Image in project CodenameOne by codenameone.
the class MediaPlayer method initComponent.
/**
* {@inheritDoc}
*/
protected void initComponent() {
if (userSetIcons) {
Image play = UIManager.getInstance().getThemeImageConstant("mediaPlayImage");
if (play != null) {
playIcon = play;
}
Image pause = UIManager.getInstance().getThemeImageConstant("mediaPauseImage");
if (pause != null) {
pauseIcon = pause;
}
Image back = UIManager.getInstance().getThemeImageConstant("mediaBackImage");
if (back != null) {
backIcon = back;
}
Image fwd = UIManager.getInstance().getThemeImageConstant("mediaFwdImage");
if (fwd != null) {
fwdIcon = fwd;
}
}
if (pendingDataURI != null) {
setDataSource(pendingDataURI);
pendingDataURI = null;
}
initUI();
}
Aggregations