All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codename1.designer.LiveDemo Maven / Gradle / Ivy

/*
 * Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Codename One designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *  
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 * 
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * Please contact Codename One through http://www.codenameone.com/ if you 
 * need additional information or have any questions.
 */
package com.codename1.designer;

import com.codename1.components.MultiButton;
import com.codename1.components.Switch;
import com.codename1.components.ToastBar;
import com.codename1.ui.Button;
import com.codename1.ui.CheckBox;
import com.codename1.ui.Command;
import com.codename1.ui.Component;
import com.codename1.ui.Container;
import com.codename1.ui.Dialog;
import com.codename1.ui.FontImage;
import com.codename1.ui.Form;
import com.codename1.ui.Label;
import com.codename1.ui.List;
import com.codename1.ui.RadioButton;
import com.codename1.ui.Slider;
import com.codename1.ui.Tabs;
import com.codename1.ui.TextField;
import com.codename1.ui.Toolbar;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import com.codename1.ui.events.DataChangedListener;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.layouts.FlowLayout;

/**
 * Quick and dirty demo of the main components within the framework allowing 
 * designers to customize the UI of the application even when no GUI is present.
 *
 * @author Shai Almog
 */
public class LiveDemo {
    public void init(Object context) {
    }
    
    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"));
        first.addComponent(FlowLayout.encloseIn(new Label("This is a switch "), new Switch()));
        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();
    }

    public void stop() {
    }
    
    public void destroy() {
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy