use of com.codename1.ui.events.ActionEvent 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.events.ActionEvent in project CodenameOne by codenameone.
the class MasterDetail method bindTabletLandscapeMaster.
/**
* @deprecated this was a half baked idea that made it into the public API
*/
public static void bindTabletLandscapeMaster(final Form rootForm, Container parentContainer, Component landscapeUI, final Component portraitUI, final String commandTitle, Image commandIcon) {
landscapeUI.setHideInPortrait(true);
parentContainer.addComponent(BorderLayout.WEST, landscapeUI);
final Command masterCommand = new Command(commandTitle, commandIcon) {
public void actionPerformed(ActionEvent ev) {
Dialog dlg = new Dialog();
dlg.setLayout(new BorderLayout());
dlg.setDialogUIID("Container");
dlg.getContentPane().setUIID("Container");
Container titleArea = new Container(new BorderLayout());
dlg.addComponent(BorderLayout.NORTH, titleArea);
titleArea.setUIID("TitleArea");
Label title = new Label(commandTitle);
titleArea.addComponent(BorderLayout.CENTER, title);
title.setUIID("Title");
Container body = new Container(new BorderLayout());
body.setUIID("Form");
body.addComponent(BorderLayout.CENTER, portraitUI);
dlg.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 250));
dlg.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 250));
dlg.addComponent(BorderLayout.CENTER, body);
dlg.setDisposeWhenPointerOutOfBounds(true);
dlg.showStetched(BorderLayout.WEST, true);
dlg.removeComponent(portraitUI);
}
};
if (Display.getInstance().isPortrait()) {
if (rootForm.getCommandCount() > 0) {
rootForm.addCommand(masterCommand, 1);
} else {
rootForm.addCommand(masterCommand);
}
}
rootForm.addOrientationListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (portraitUI.getParent() != null) {
Form f = Display.getInstance().getCurrent();
if (f instanceof Dialog) {
((Dialog) f).dispose();
}
}
if (Display.getInstance().isPortrait()) {
rootForm.addCommand(masterCommand, 1);
} else {
rootForm.removeCommand(masterCommand);
rootForm.revalidate();
}
}
});
}
use of com.codename1.ui.events.ActionEvent 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.events.ActionEvent in project CodenameOne by codenameone.
the class Progress method actionPerformed.
/**
* {@inheritDoc}
*/
public void actionPerformed(ActionEvent evt) {
NetworkEvent ev = (NetworkEvent) evt;
if (ev.getConnectionRequest() == request) {
if (disposeOnCompletion && ev.getProgressType() == NetworkEvent.PROGRESS_TYPE_COMPLETED) {
dispose();
return;
}
if (autoShow && !showing) {
showing = true;
showModeless();
}
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Ads method setAd.
/**
* HTML ad received from the server
* @param ad the ad to set
*/
public void setAd(String ad) {
HTMLComponent html = new HTMLComponent(new AsyncDocumentRequestHandlerImpl() {
protected ConnectionRequest createConnectionRequest(DocumentInfo docInfo, IOCallback callback, Object[] response) {
ConnectionRequest req = super.createConnectionRequest(docInfo, callback, response);
req.setFailSilently(true);
req.addResponseCodeListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// do nothing, just make sure the html won't throw an error
}
});
return req;
}
});
html.setSupressExceptions(true);
html.setHTMLCallback(this);
html.setBodyText("<html><body><div align='center'>" + ad + "</div></body></html>");
replace(getComponentAt(0), html, null);
revalidate();
html.setPageUIID("Container");
html.getStyle().setBgTransparency(0);
}
Aggregations