Search in sources :

Example 56 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class JavaSEPort method getTransform.

@Override
public void getTransform(Object graphics, Transform transform) {
    checkEDT();
    com.codename1.ui.Transform t = getNativeScreenGraphicsTransform(graphics);
    if (t == null) {
        transform.setIdentity();
    } else {
        transform.setTransform(t);
    }
}
Also used : Transform(com.codename1.ui.Transform)

Example 57 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class JavaSEPort method deepRevaliate.

private void deepRevaliate(com.codename1.ui.Container c) {
    c.setShouldCalcPreferredSize(true);
    for (int iter = 0; iter < c.getComponentCount(); iter++) {
        com.codename1.ui.Component cmp = c.getComponentAt(iter);
        cmp.setShouldCalcPreferredSize(true);
        if (cmp instanceof com.codename1.ui.Container) {
            deepRevaliate((com.codename1.ui.Container) cmp);
        }
    }
}
Also used : Component(com.codename1.ui.Component) Point(java.awt.Point)

Example 58 with com.codename1.io

use of com.codename1.io 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);
}
Also used : Transform(com.codename1.ui.Transform)

Example 59 with com.codename1.io

use of com.codename1.io 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);
            }
        });
    }
}
Also used : AttributedString(java.text.AttributedString) Preferences(java.util.prefs.Preferences) Display(com.codename1.ui.Display)

Example 60 with com.codename1.io

use of com.codename1.io 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);
}
Also used : TextArea(com.codename1.ui.TextArea) UITimer(com.codename1.ui.util.UITimer) Timer(java.util.Timer) AttributedString(java.text.AttributedString) JTextComponent(javax.swing.text.JTextComponent) Point(java.awt.Point) java.util(java.util) UITimer(com.codename1.ui.util.UITimer) Timer(java.util.Timer) java.awt(java.awt)

Aggregations

IOException (java.io.IOException)39 EncodedImage (com.codename1.ui.EncodedImage)29 ArrayList (java.util.ArrayList)27 Point (java.awt.Point)25 File (java.io.File)24 BufferedImage (java.awt.image.BufferedImage)23 AnimationObject (com.codename1.ui.animations.AnimationObject)22 Form (com.codename1.ui.Form)19 Hashtable (java.util.Hashtable)19 Component (com.codename1.ui.Component)18 Image (com.codename1.ui.Image)18 EditableResources (com.codename1.ui.util.EditableResources)16 FileInputStream (java.io.FileInputStream)16 Timeline (com.codename1.ui.animations.Timeline)15 BorderLayout (com.codename1.ui.layouts.BorderLayout)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)11 FileOutputStream (java.io.FileOutputStream)10 EditorFont (com.codename1.ui.EditorFont)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9