Search in sources :

Example 56 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class DateTimeSpinner3D method calcPreferredSize.

@Override
protected Dimension calcPreferredSize() {
    Dimension size = super.calcPreferredSize();
    Label l = new Label("Thu Dec 27    55  55  AM", "Spinner3DRow");
    size.setWidth((int) (l.getPreferredW() * 1.5f + convertToPixels(10f)));
    return size;
}
Also used : Label(com.codename1.ui.Label) Dimension(com.codename1.ui.geom.Dimension)

Example 57 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class DateTimeSpinner3D method initSpinner.

void initSpinner() {
    if (date == null) {
        date = Spinner3D.createDate(startDate.getTime() + off, endDate.getTime() + off, currentDate.getTime());
        date.setPreferredW((int) (new Label("Thu Dec 27", "Spinner3DRow").getPreferredW() * 1.5f));
        Style dateStyle = Style.createProxyStyle(date.getRowStyle(), date.getSelectedRowStyle());
        dateStyle.setAlignment(Component.RIGHT);
        dateStyle.setPaddingRight(3f);
        this.setCurrentDate(currentDate);
        this.setStartDate(startDate);
        this.setEndDate(endDate);
        time = new TimeSpinner3D();
        // getUnselectedStyle().setBgColor(date.getUnselectedStyle().getBgColor());
        // getUnselectedStyle().setBgTransparency(255);
        addComponents();
    }
}
Also used : Label(com.codename1.ui.Label) Style(com.codename1.ui.plaf.Style)

Example 58 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class Validator method trimLongString.

/**
 * Long error messages are trimmed to fit the available space in the layout
 *
 * @param errorMessage the string to be trimmed
 * @param uiid the uiid of the errorMessage
 * @param width the maximum width
 * @return the new String trimmed to fit the available width
 */
private String trimLongString(String errorMessage, String uiid, int width) {
    Label errorLabel = new Label(errorMessage, uiid);
    while (errorLabel.getPreferredW() > width && errorMessage.length() > 1) {
        errorMessage = errorMessage.substring(0, errorMessage.length() - 1);
        errorLabel.setText(errorMessage);
    }
    return errorMessage;
}
Also used : Label(com.codename1.ui.Label)

Example 59 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class JavaSEPort method downloadSkin.

private File downloadSkin(File skinDir, String url, String version, JLabel label) throws IOException {
    String fileName = url.substring(url.lastIndexOf("/"));
    File skin = new File(skinDir.getAbsolutePath() + "/" + fileName);
    HttpURLConnection.setFollowRedirects(true);
    URL u = new URL(url);
    FileOutputStream os = new FileOutputStream(skin);
    URLConnection uc = u.openConnection();
    InputStream is = uc.getInputStream();
    int length = uc.getContentLength();
    byte[] buffer = new byte[65536];
    int size = is.read(buffer);
    int offset = 0;
    int percent = 0;
    String msg = label.getText();
    if (length > 0) {
        System.out.println("Downloading " + length + " bytes");
    }
    while (size > -1) {
        offset += size;
        if (length > 0) {
            float f = ((float) offset) / ((float) length) * 100;
            if (percent != ((int) f)) {
                percent = (int) f;
                label.setText(msg + " " + percent + "%");
                label.repaint();
            }
        } else {
            if (percent < offset / 102400) {
                percent = offset / 102400;
                System.out.println("Downloaded " + percent + "00Kb");
            }
        }
        os.write(buffer, 0, size);
        size = is.read(buffer);
    }
    is.close();
    os.close();
    // store the skin version
    Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
    pref.put(fileName, version);
    return skin;
}
Also used : BufferedInputStream(com.codename1.io.BufferedInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) AudioInputStream(javax.sound.sampled.AudioInputStream) ZipInputStream(java.util.zip.ZipInputStream) AttributedString(java.text.AttributedString) Preferences(java.util.prefs.Preferences) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Point(java.awt.Point)

Example 60 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class GameCanvasImplementation method captureAudio.

public void captureAudio(ActionListener response) {
    captureResponse = response;
    try {
        final Form current = Display.getInstance().getCurrent();
        final MMAPIPlayer player = MMAPIPlayer.createPlayer("capture://audio", null);
        RecordControl record = (RecordControl) player.nativePlayer.getControl("RecordControl");
        if (record == null) {
            player.cleanup();
            throw new RuntimeException("Capture Audio is not supported on this device");
        }
        final Form cam = new Form();
        cam.setTransitionInAnimator(CommonTransitions.createEmpty());
        cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
        cam.setLayout(new BorderLayout());
        cam.show();
        player.play();
        final Label time = new Label("0:00");
        cam.addComponent(BorderLayout.SOUTH, time);
        cam.revalidate();
        ActionListener l = new ActionListener() {

            boolean recording = false;

            OutputStream out = null;

            String audioPath = null;

            RecordControl record;

            public void actionPerformed(ActionEvent evt) {
                if (!recording) {
                    record = (RecordControl) player.nativePlayer.getControl("RecordControl");
                    recording = true;
                    String type = record.getContentType();
                    String prefix = "";
                    if (type.endsWith("wav")) {
                        prefix = ".wav";
                    } else if (type.endsWith("amr")) {
                        prefix = ".amr";
                    } else if (type.endsWith("3gpp")) {
                        prefix = ".3gp";
                    }
                    audioPath = getOutputMediaFile() + prefix;
                    try {
                        out = FileSystemStorage.getInstance().openOutputStream(audioPath);
                        record.setRecordStream(out);
                        record.startRecord();
                        cam.registerAnimated(new Animation() {

                            long current = System.currentTimeMillis();

                            long zero = current;

                            int sec = 0;

                            public boolean animate() {
                                long now = System.currentTimeMillis();
                                if (now - current > 1000) {
                                    current = now;
                                    sec++;
                                    return true;
                                }
                                return false;
                            }

                            public void paint(Graphics g) {
                                String txt = sec / 60 + ":" + sec % 60;
                                time.setText(txt);
                            }
                        });
                    } catch (IOException ex) {
                        ex.printStackTrace();
                        System.out.println("failed to store audio to " + audioPath);
                    } finally {
                    }
                } else {
                    if (out != null) {
                        try {
                            record.stopRecord();
                            record.commit();
                            out.close();
                            player.cleanup();
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                    captureResponse.actionPerformed(new ActionEvent(audioPath));
                    current.showBack();
                }
            }
        };
        cam.addGameKeyListener(Display.GAME_FIRE, l);
        cam.addPointerReleasedListener(l);
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new RuntimeException("failed to start camera");
    }
}
Also used : Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(com.codename1.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) Graphics(com.codename1.ui.Graphics) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Animation(com.codename1.ui.animations.Animation) RecordControl(javax.microedition.media.control.RecordControl)

Aggregations

Label (com.codename1.ui.Label)129 Form (com.codename1.ui.Form)95 Button (com.codename1.ui.Button)50 BorderLayout (com.codename1.ui.layouts.BorderLayout)50 Container (com.codename1.ui.Container)49 Component (com.codename1.ui.Component)27 SpanLabel (com.codename1.components.SpanLabel)26 Style (com.codename1.ui.plaf.Style)24 BoxLayout (com.codename1.ui.layouts.BoxLayout)19 TextArea (com.codename1.ui.TextArea)18 ActionEvent (com.codename1.ui.events.ActionEvent)18 IOException (java.io.IOException)18 Image (com.codename1.ui.Image)17 Dimension (com.codename1.ui.geom.Dimension)16 TextField (com.codename1.ui.TextField)15 ActionListener (com.codename1.ui.events.ActionListener)15 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)15 Toolbar (com.codename1.ui.Toolbar)13 FlowLayout (com.codename1.ui.layouts.FlowLayout)12 EncodedImage (com.codename1.ui.EncodedImage)11