Search in sources :

Example 61 with Label

use of com.codename1.ui.Label in project CodenameOne by codenameone.

the class BaseSpinner method createSeparator.

Component createSeparator() {
    Label l = new Label(" ") {

        public void repaint() {
            getParent().repaint();
        }
    };
    l.setUIID("SpinnerSeparator");
    return l;
}
Also used : Label(com.codename1.ui.Label)

Example 62 with Label

use of com.codename1.ui.Label in project CodenameOne by codenameone.

the class TimeSpinner method addComponents.

void addComponents() {
    setLayout(new LayeredLayout());
    LayeredLayout ll = (LayeredLayout) getLayout();
    Container content = new Container(BoxLayout.x());
    Style allStyles = content.getAllStyles();
    allStyles.setMargin(0, 0, 0, 0);
    allStyles.setPadding(0, 0, 0, 0);
    allStyles.setBgTransparency(0);
    allStyles.setBorder(Border.createEmpty());
    if (amPM != null) {
        content.addComponent(hour);
        hourComponents.add(hour);
        if (durationMode) {
            Label l = new Label(getUIManager().localize("hours", "hours"));
            l.setUIID("TimeSpinnerHoursLabel");
            hourComponents.add(l);
            content.addComponent(l);
        }
        content.addComponent(createSeparator());
        content.addComponent(minute);
        minuteComponents.add(minute);
        if (durationMode) {
            Label l = new Label(getUIManager().localize("minutes", "minutes"));
            l.setUIID("TimeSpinnerMinutesLabel");
            minuteComponents.add(l);
            content.addComponent(l);
        }
        if (showMeridiem) {
            content.addComponent(createSeparator());
            content.addComponent(amPM);
        }
    }
    setHoursVisible(showHours);
    setMinutesVisible(showMinutes);
    addComponent(content);
    ll.setInsets(content, "0 auto 0 auto");
}
Also used : Container(com.codename1.ui.Container) Label(com.codename1.ui.Label) Style(com.codename1.ui.plaf.Style) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 63 with Label

use of com.codename1.ui.Label in project CodenameOne by codenameone.

the class LiveDemo method start.

public void start() {
    Form previewForm = new Form("Preview Theme");
    Toolbar tb = new Toolbar();
    previewForm.setToolbar(tb);
    tb.setTitle("Preview Theme");
    tb.addMaterialCommandToSideMenu("Side Command", FontImage.MATERIAL_HELP, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            ToastBar.showErrorMessage("Unmapped....");
        }
    });
    tb.addMaterialCommandToOverflowMenu("Overflow Command", FontImage.MATERIAL_HELP, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            ToastBar.showErrorMessage("Unmapped....");
        }
    });
    tb.addMaterialCommandToRightBar("", FontImage.MATERIAL_HELP, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            ToastBar.showErrorMessage("Unmapped....");
        }
    });
    previewForm.setLayout(new BorderLayout());
    Container first = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    first.addComponent(new Label("This is a Label"));
    first.addComponent(new Button("This is a Button"));
    MultiButton mb = new MultiButton("This is a MultiButton");
    mb.setTextLine2("Second line of text");
    FontImage.setMaterialIcon(mb, FontImage.MATERIAL_HELP);
    first.addComponent(mb);
    TextField txt = new TextField();
    txt.setHint("This is a TextField");
    first.addComponent(txt);
    first.addComponent(new CheckBox("This is a CheckBox"));
    RadioButton rb1 = new RadioButton("This is a Radio Button 1");
    rb1.setGroup("group");
    first.addComponent(rb1);
    RadioButton rb2 = new RadioButton("This is a Radio Button 2");
    rb2.setGroup("group");
    first.addComponent(rb2);
    final Slider s = new Slider();
    s.setText("50%");
    s.setProgress(50);
    s.setEditable(true);
    s.setRenderPercentageOnTop(true);
    first.addComponent(s);
    Button b1 = new Button("Show a Dialog");
    b1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            Dialog.show("Dialog Title", "Dialog Body", "Ok", "Cancel");
        }
    });
    first.addComponent(b1);
    previewForm.add(BorderLayout.CENTER, first);
    previewForm.show();
}
Also used : Slider(com.codename1.ui.Slider) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label) RadioButton(com.codename1.ui.RadioButton) Container(com.codename1.ui.Container) ActionListener(com.codename1.ui.events.ActionListener) BorderLayout(com.codename1.ui.layouts.BorderLayout) RadioButton(com.codename1.ui.RadioButton) Button(com.codename1.ui.Button) MultiButton(com.codename1.components.MultiButton) CheckBox(com.codename1.ui.CheckBox) TextField(com.codename1.ui.TextField) MultiButton(com.codename1.components.MultiButton) Toolbar(com.codename1.ui.Toolbar)

Example 64 with Label

use of com.codename1.ui.Label in project CodenameOne by codenameone.

the class ResourceEditorView method createFileChooser.

public static JFileChooser createFileChooser(final String label, final String... type) {
    String dir = Preferences.userNodeForPackage(ResourceEditorView.class).get("lastDir", System.getProperty("user.home"));
    JFileChooser chooser = new JFileChooser(dir);
    chooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }
            for (String s : type) {
                if (f.getName().toLowerCase().endsWith(s)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public String getDescription() {
            return label;
        }
    });
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    return chooser;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride) File(java.io.File)

Example 65 with Label

use of com.codename1.ui.Label in project CodenameOne by codenameone.

the class TimelineEditor method selectFile.

/**
 * Selects a gif file using a file chooser and converts it to a timeline
 */
public static void selectFile(ResourceEditorView view, EditableResources res, String timelineName) {
    File[] files = ResourceEditorView.showOpenFileChooser("Images", ".gif");
    if (files != null) {
        File sel = files[0];
        if (timelineName == null) {
            timelineName = sel.getName();
        }
        Preferences.userNodeForPackage(view.getClass()).put("lastDir", sel.getParentFile().getAbsolutePath());
        ImageReader iReader = ImageIO.getImageReadersBySuffix("gif").next();
        try {
            iReader.setInput(ImageIO.createImageInputStream(new FileInputStream(sel)));
            int frames = iReader.getNumImages(true);
            AnimationObject[] anims = new AnimationObject[frames];
            int currentTime = 0;
            for (int frameIter = 0; frameIter < frames; frameIter++) {
                BufferedImage currentImage = iReader.read(frameIter);
                ByteArrayOutputStream bo = new ByteArrayOutputStream();
                ImageIO.write(currentImage, "png", bo);
                bo.close();
                // create a PNG image in the resource file
                String label = sel.getName() + " frame:" + frameIter;
                EncodedImage i = EncodedImage.create(bo.toByteArray());
                res.setImage(label, i);
                int duration = Math.max(40, AnimationImpl.getFrameTime(iReader, frameIter));
                Point pos = AnimationImpl.getPixelOffsets(iReader, frameIter);
                anims[frameIter] = AnimationObject.createAnimationImage(i, pos.x, pos.y);
                anims[frameIter].setStartTime(currentTime);
                anims[frameIter].setEndTime(100000000);
                String disposeMethod = getDisposalMethod(iReader, frameIter);
                if (disposeMethod != null) {
                    if ("restoreToBackgroundColor".equals(disposeMethod)) {
                        if (frameIter + 1 < frames) {
                            int t = Math.max(40, AnimationImpl.getFrameTime(iReader, frameIter + 1));
                            anims[frameIter].setEndTime(currentTime + t);
                        } else {
                            anims[frameIter].setEndTime(currentTime + duration);
                        }
                    // for(int iter = frameIter ; iter >= 0 ; iter--) {
                    // anims[iter].setEndTime(currentTime);
                    // }
                    }
                // "none" |
                // "doNotDispose" | "restoreToBackgroundColor" |
                // "restoreToPrevious"
                }
                currentTime += duration;
            }
            Timeline t = Timeline.createTimeline(currentTime, anims, new com.codename1.ui.geom.Dimension(iReader.getWidth(0), iReader.getHeight(0)));
            res.setImage(timelineName, t);
            view.setSelectedResource(timelineName);
        } catch (IOException err) {
            err.printStackTrace();
            JOptionPane.showMessageDialog(JFrame.getFrames()[0], "Error reading file " + err, "IO Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Point(java.awt.Point) IOException(java.io.IOException) EncodedImage(com.codename1.ui.EncodedImage) FileInputStream(java.io.FileInputStream) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) ImageReader(javax.imageio.ImageReader) File(java.io.File)

Aggregations

Label (com.codename1.ui.Label)41 BorderLayout (com.codename1.ui.layouts.BorderLayout)22 Container (com.codename1.ui.Container)21 Component (com.codename1.ui.Component)16 Form (com.codename1.ui.Form)15 Button (com.codename1.ui.Button)14 TextArea (com.codename1.ui.TextArea)14 Style (com.codename1.ui.plaf.Style)13 ActionListener (com.codename1.ui.events.ActionListener)12 ActionEvent (com.codename1.ui.events.ActionEvent)11 Image (com.codename1.ui.Image)10 Dimension (com.codename1.ui.geom.Dimension)10 Vector (java.util.Vector)10 BoxLayout (com.codename1.ui.layouts.BoxLayout)9 EncodedImage (com.codename1.ui.EncodedImage)8 RadioButton (com.codename1.ui.RadioButton)7 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Hashtable (java.util.Hashtable)6 Paint (com.codename1.charts.compat.Paint)5 Font (com.codename1.ui.Font)5