use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class JavaSEPort method rotate.
public void rotate(Object nativeGraphics, float angle, int pX, int pY) {
checkEDT();
// Graphics2D g = getGraphics(nativeGraphics);
// g.rotate(angle, pX, pY);
com.codename1.ui.Transform tf = getTransform(nativeGraphics);
tf.rotate(angle, pX, pY);
setTransform(nativeGraphics, tf);
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class JavaSEPort method registerPush.
@Override
public void registerPush(Hashtable meta, boolean noFallback) {
Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
String user = p.get("user", null);
Display d = Display.getInstance();
if (user == null) {
JPanel pnl = new JPanel();
JTextField tf = new JTextField(20);
pnl.add(new JLabel("E-Mail For Push"));
pnl.add(tf);
JOptionPane.showMessageDialog(canvas, pnl, "Email For Push", JOptionPane.PLAIN_MESSAGE);
user = tf.getText();
p.put("user", user);
}
d.setProperty("built_by_user", user);
String mainClass = System.getProperty("MainClass");
if (mainClass != null) {
mainClass = mainClass.substring(0, mainClass.lastIndexOf('.'));
d.setProperty("package_name", mainClass);
}
super.registerPush(meta, noFallback);
if (pushSimulation != null && pushSimulation.isVisible()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(window, "registerForPush invoked. Use the buttons in the push simulator to send the appropriate callback to your app", "Push Registration", JOptionPane.INFORMATION_MESSAGE);
}
});
}
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class JavaSEPort method editStringLegacy.
public void editStringLegacy(final Component cmp, int maxSize, int constraint, String text, int keyCode) {
checkEDT();
java.awt.Component awtTf;
if (cmp instanceof com.codename1.ui.TextField) {
java.awt.TextField t = new java.awt.TextField();
awtTf = t;
t.setSelectionEnd(0);
t.setSelectionStart(0);
} else {
java.awt.TextArea t = new java.awt.TextArea("", 0, 0, java.awt.TextArea.SCROLLBARS_NONE);
;
awtTf = t;
t.setSelectionEnd(0);
t.setSelectionStart(0);
}
final java.awt.Component tf = awtTf;
if (keyCode > 0) {
text += ((char) keyCode);
setText(tf, text);
setCaretPosition(tf, text.length());
((com.codename1.ui.TextField) cmp).setText(getText(tf));
} else {
setText(tf, text);
}
canvas.add(tf);
if (getSkin() != null) {
tf.setBounds((int) ((cmp.getAbsoluteX() + getScreenCoordinates().x + canvas.x) * zoomLevel), (int) ((cmp.getAbsoluteY() + getScreenCoordinates().y + canvas.y) * zoomLevel), (int) (cmp.getWidth() * zoomLevel), (int) (cmp.getHeight() * zoomLevel));
java.awt.Font f = font(cmp.getStyle().getFont().getNativeFont());
tf.setFont(f.deriveFont(f.getSize2D() * zoomLevel));
} else {
tf.setBounds(cmp.getAbsoluteX(), cmp.getAbsoluteY(), cmp.getWidth(), cmp.getHeight());
tf.setFont(font(cmp.getStyle().getFont().getNativeFont()));
}
setCaretPosition(tf, getText(tf).length());
tf.requestFocus();
class Listener implements ActionListener, FocusListener, KeyListener, TextListener, Runnable {
public synchronized void run() {
while (tf.getParent() != null) {
try {
wait(20);
} catch (InterruptedException ex) {
}
}
}
public void actionPerformed(ActionEvent e) {
String txt = getText(tf);
if (testRecorder != null) {
testRecorder.editTextFieldCompleted(cmp, txt);
}
Display.getInstance().onEditingComplete(cmp, txt);
if (tf instanceof java.awt.TextField) {
((java.awt.TextField) tf).removeActionListener(this);
}
((TextComponent) tf).removeTextListener(this);
tf.removeFocusListener(this);
canvas.remove(tf);
synchronized (this) {
notify();
}
canvas.repaint();
}
public void focusGained(FocusEvent e) {
setCaretPosition(tf, getText(tf).length());
}
public void focusLost(FocusEvent e) {
actionPerformed(null);
}
public void keyTyped(KeyEvent e) {
String t = getText(tf);
if (t.length() >= ((TextArea) cmp).getMaxSize()) {
e.consume();
}
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
if (tf instanceof java.awt.TextField) {
actionPerformed(null);
} else {
if (getCaretPosition(tf) >= getText(tf).length() - 1) {
actionPerformed(null);
}
}
return;
}
if (e.getKeyCode() == KeyEvent.VK_UP) {
if (tf instanceof java.awt.TextField) {
actionPerformed(null);
} else {
if (getCaretPosition(tf) <= 2) {
actionPerformed(null);
}
}
return;
}
}
public void textValueChanged(TextEvent e) {
if (cmp instanceof com.codename1.ui.TextField) {
((com.codename1.ui.TextField) cmp).setText(getText(tf));
}
}
}
;
final Listener l = new Listener();
if (tf instanceof java.awt.TextField) {
((java.awt.TextField) tf).addActionListener(l);
}
((TextComponent) tf).addTextListener(l);
tf.addKeyListener(l);
tf.addFocusListener(l);
if (simulateAndroidKeyboard) {
java.util.Timer t = new java.util.Timer();
TimerTask tt = new TimerTask() {
@Override
public void run() {
if (!Display.getInstance().isEdt()) {
Display.getInstance().callSerially(this);
return;
}
if (tf.getParent() != null) {
final int height = getScreenCoordinates().height;
JavaSEPort.this.sizeChanged(getScreenCoordinates().width, height / 2);
new UITimer(new Runnable() {
public void run() {
if (tf.getParent() != null) {
new UITimer(this).schedule(100, false, Display.getInstance().getCurrent());
} else {
JavaSEPort.this.sizeChanged(getScreenCoordinates().width, height);
}
}
}).schedule(100, false, Display.getInstance().getCurrent());
}
}
};
t.schedule(tt, 300);
}
Display.getInstance().invokeAndBlock(l);
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class BlackBerryImplementation method sendMessage.
public void sendMessage(String[] recipients, String subject, Message msg) {
Folder[] folders = Session.getDefaultInstance().getStore().list(Folder.SENT);
net.rim.blackberry.api.mail.Message message = new net.rim.blackberry.api.mail.Message(folders[0]);
try {
Address[] toAdds = new Address[recipients.length];
for (int i = 0; i < recipients.length; i++) {
Address address = new Address(recipients[i], "");
toAdds[i] = address;
}
message.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, toAdds);
message.setSubject(subject);
} catch (Exception e) {
EventLog.getInstance().logErrorEvent("err " + e.getMessage());
}
try {
if (msg.getAttachment() != null && msg.getAttachment().length() > 0) {
Multipart content = new Multipart();
TextBodyPart tbp = new TextBodyPart(content, msg.getContent());
content.addBodyPart(tbp);
InputStream stream = com.codename1.io.FileSystemStorage.getInstance().openInputStream(msg.getAttachment());
byte[] buf;
buf = IOUtilities.streamToBytes(stream);
stream.close();
String name = msg.getAttachment();
name = name.substring(name.lastIndexOf(getFileSystemSeparator()) + 1, name.length());
SupportedAttachmentPart sap = new SupportedAttachmentPart(content, msg.getAttachmentMimeType(), name, buf);
content.addBodyPart(sap);
message.setContent(content);
} else {
message.setContent(msg.getContent());
}
app.setWaitingForReply(true);
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));
} catch (Exception ex) {
EventLog.getInstance().logErrorEvent("err " + ex.getMessage());
}
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class GameCanvasImplementation method capturePhoto.
public void capturePhoto(ActionListener response) {
captureResponse = response;
final Form current = Display.getInstance().getCurrent();
final Form cam = new Form();
cam.setScrollable(false);
cam.setTransitionInAnimator(CommonTransitions.createEmpty());
cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
cam.setLayout(new BorderLayout());
cam.show();
String platform = System.getProperty("microedition.platform");
MMAPIPlayer p = null;
if (platform != null && platform.indexOf("Nokia") >= 0) {
try {
p = MMAPIPlayer.createPlayer("capture://image", null);
} catch (Throwable e) {
// Ignore all exceptions for image capture, continue with video capture...
}
}
if (p == null) {
try {
p = MMAPIPlayer.createPlayer("capture://video", null);
} catch (Exception e) {
// The Nokia 2630 throws this if image/video capture is not supported
throw new RuntimeException("Image/video capture not supported on this phone");
}
}
final MMAPIPlayer player = p;
MIDPVideoComponent video = new MIDPVideoComponent(player, canvas);
video.play();
video.setVisible(true);
cam.addCommand(new com.codename1.ui.Command("Cancel") {
public void actionPerformed(ActionEvent evt) {
if (player != null) {
player.cleanup();
}
captureResponse.actionPerformed(null);
current.showBack();
}
});
final ActionListener l = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
cam.removeAll();
VideoControl cnt = (VideoControl) player.nativePlayer.getControl("VideoControl");
byte[] pic = cnt.getSnapshot("encoding=jpeg&width=" + current.getWidth() + "&height=" + current.getHeight());
String imagePath = getOutputMediaFile() + ".jpg";
OutputStream out = null;
try {
if (pic != null) {
out = FileSystemStorage.getInstance().openOutputStream(imagePath);
out.write(pic);
}
} catch (Throwable ex) {
ex.printStackTrace();
System.out.println("failed to store picture to " + imagePath);
} finally {
try {
if (out != null) {
out.close();
}
player.cleanup();
} catch (Throwable ex) {
ex.printStackTrace();
}
}
captureResponse.actionPerformed(new ActionEvent(imagePath));
current.showBack();
} catch (Throwable ex) {
ex.printStackTrace();
System.out.println("failed to take picture");
current.showBack();
}
}
};
cam.addGameKeyListener(Display.GAME_FIRE, l);
Container cn = new Container(new BorderLayout()) {
public void pointerReleased(int x, int y) {
l.actionPerformed(null);
}
};
cn.setFocusable(true);
cn.addComponent(BorderLayout.CENTER, video);
cam.addComponent(BorderLayout.CENTER, cn);
cam.revalidate();
// cam.addPointerReleasedListener(l);
}
Aggregations