use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class VServAds method getPendingAd.
/**
* {@inheritDoc}
*/
protected Component getPendingAd() {
if (imageURL == null) {
return null;
}
if (renderNotify != null && renderNotify.length() > 0) {
ConnectionRequest c = new ConnectionRequest();
c.setFailSilently(true);
c.setUrl(renderNotify);
c.setPost(false);
NetworkManager.getInstance().addToQueue(c);
}
if ("image".equalsIgnoreCase(contentType)) {
Button adComponent = new Button() {
public void setIcon(Image icon) {
if (icon != null && isScaleMode()) {
icon = icon.scaledWidth(Display.getInstance().getDisplayWidth());
}
super.setIcon(icon);
}
};
adComponent.setUIID("Container");
adComponent.getStyle().setBgColor(backgroundColor);
adComponent.getStyle().setOpacity(0xff);
ImageDownloadService imd = new ImageDownloadService(imageURL, adComponent);
NetworkManager.getInstance().addToQueueAndWait(imd);
/*adComponent.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Display.getInstance().execute(getAdDestination());
}
});*/
return adComponent;
} else {
WebBrowser wb = new WebBrowser();
if (wb.getInternal() instanceof BrowserComponent) {
BrowserComponent bc = (BrowserComponent) wb.getInternal();
bc.setBrowserNavigationCallback(new BrowserNavigationCallback() {
public boolean shouldNavigate(final String url) {
unlock(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Display.getInstance().execute(url);
}
});
return false;
}
});
}
wb.setURL(imageURL);
return wb;
}
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class MediaPlayer method initUI.
private void initUI() {
removeAll();
setLayout(new BorderLayout());
if (video != null && video.getVideoComponent() != null) {
Component videoComponent = video.getVideoComponent();
if (videoComponent != null) {
addComponent(BorderLayout.CENTER, videoComponent);
}
}
buttonsBar = new Container(new FlowLayout(Container.CENTER));
addComponent(BorderLayout.SOUTH, buttonsBar);
if (usesNativeVideoControls() || !showControls) {
buttonsBar.setVisible(false);
buttonsBar.setHidden(true);
}
// if(video == null || !video.isNativePlayerMode()){
Button back = new Button();
back.setUIID("MediaPlayerBack");
if (backIcon != null) {
back.setIcon(backIcon);
} else {
back.setText("Back");
}
buttonsBar.addComponent(back);
back.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (video == null) {
return;
}
int t = video.getTime();
video.setTime(t - 2);
}
});
// }
final Button play = new Button();
play.setUIID("MediaPlayerPlay");
if (playIcon != null) {
play.setIcon(playIcon);
} else {
play.setText("play");
}
if (autoplay) {
if (video != null && !video.isPlaying()) {
if (getPauseIcon() != null) {
play.setIcon(getPauseIcon());
} else {
play.setText("pause");
}
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
if (isInitialized()) {
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (video != null && !video.isPlaying() && isInitialized()) {
video.play();
}
}
});
}
}
}, 300l);
// video.play();
}
}
play.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (video == null) {
return;
}
if (!video.isPlaying()) {
video.play();
play.setUIID("MediaPlayerPause");
if (getPauseIcon() != null) {
play.setIcon(getPauseIcon());
} else {
play.setText("pause");
}
play.repaint();
} else {
video.pause();
play.setUIID("MediaPlayerPlay");
if (getPlayIcon() != null) {
play.setIcon(getPlayIcon());
} else {
play.setText("play");
}
play.repaint();
}
}
});
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (video != null && video.isPlaying()) {
play.setUIID("MediaPlayerPause");
if (getPauseIcon() != null) {
play.setIcon(getPauseIcon());
} else {
play.setText("pause");
}
} else if (video != null && !video.isPlaying()) {
play.setUIID("MediaPlayerPlay");
if (getPlayIcon() != null) {
play.setIcon(getPlayIcon());
} else {
play.setText("play");
}
}
}
});
buttonsBar.addComponent(play);
// if(video == null || !video.isNativePlayerMode()){
Button fwd = new Button();
fwd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (video == null) {
return;
}
int t = video.getTime();
video.setTime(t + 1);
}
});
fwd.setUIID("MediaPlayerFwd");
if (fwdIcon != null) {
fwd.setIcon(fwdIcon);
} else {
fwd.setText("fwd");
}
buttonsBar.addComponent(fwd);
// }
if (isInitialized()) {
revalidate();
}
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class MultiButton method setCheckBox.
/**
* Turns the multi-button into a checkbox multi-button
*
* @param b true for a checkbox multi-button
*/
public void setCheckBox(boolean b) {
if (b != isCheckBox()) {
Container par = emblem.getParent();
Button old = emblem;
if (b) {
emblem = new CheckBox();
} else {
emblem = new Button();
}
emblem.setUIID(old.getUIID());
emblem.setName(old.getName());
java.util.List actionListeners = (java.util.List) old.getListeners();
if (actionListeners != null) {
for (int iter = 0; iter < actionListeners.size(); iter++) {
emblem.addActionListener((ActionListener) actionListeners.get(iter));
}
}
if (old.getCommand() != null) {
Image img = old.getIcon();
emblem.setCommand(old.getCommand());
emblem.setText("");
emblem.setIcon(img);
} else {
emblem.setText(old.getText());
if (old.getIcon() != null) {
emblem.setIcon(old.getIcon());
}
}
par.replace(old, emblem, null);
setLeadComponent(emblem);
}
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class MultiButton method setLinesTogetherMode.
/**
* Changes the layout so the lines of the button are grouped together
* @param l true to group the lines together
*/
public void setLinesTogetherMode(boolean l) {
if (l != isLinesTogetherMode()) {
if (l) {
firstRow.getParent().removeComponent(firstRow);
Container p = secondRow.getParent();
p.addComponent(0, firstRow);
Container pp = p.getParent();
pp.removeComponent(p);
pp.addComponent(BorderLayout.CENTER, p);
} else {
secondRow.getParent().removeComponent(secondRow);
thirdRow.getParent().addComponent(0, secondRow);
}
}
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class MultiButton method setRadioButton.
/**
* Turns the multi-button into a radio multi-button
*
* @param b true for a radio multi-button
*/
public void setRadioButton(boolean b) {
if (b != isRadioButton()) {
Container par = emblem.getParent();
Button old = emblem;
if (b) {
emblem = new RadioButton();
if (group != null) {
((RadioButton) emblem).setGroup(group);
}
} else {
emblem = new Button();
}
emblem.setName(old.getName());
emblem.setUIID(old.getUIID());
java.util.List actionListeners = (java.util.List) old.getListeners();
if (actionListeners != null) {
for (int iter = 0; iter < actionListeners.size(); iter++) {
emblem.addActionListener((ActionListener) actionListeners.get(iter));
}
}
if (old.getCommand() != null) {
Image img = old.getIcon();
emblem.setCommand(old.getCommand());
emblem.setText("");
emblem.setIcon(img);
}
par.replace(old, emblem, null);
setLeadComponent(emblem);
emblem.setShowEvenIfBlank(true);
}
}
Aggregations