Search in sources :

Example 46 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class InfiniteProgress method showInifiniteBlocking.

/**
 * Shows the infinite progress over the whole screen, the blocking can be competed by calling <code>dispose()</code>
 * on the returned <code>Dialog</code>.
 *<script src="https://gist.github.com/codenameone/a0a6abca781cd86e4f5e.js"></script>
 * @return the dialog created for the blocking effect, disposing it will return to the previous form and remove the input block.
 */
public Dialog showInifiniteBlocking() {
    Form f = Display.getInstance().getCurrent();
    if (f == null) {
        f = new Form();
        f.show();
    }
    if (f.getClientProperty("isInfiniteProgress") == null) {
        f.setTintColor(tintColor);
    }
    Dialog d = new Dialog();
    d.putClientProperty("isInfiniteProgress", true);
    d.setTintColor(0x0);
    d.setDialogUIID("Container");
    d.setLayout(new BorderLayout());
    d.addComponent(BorderLayout.CENTER, this);
    d.setTransitionInAnimator(CommonTransitions.createEmpty());
    d.setTransitionOutAnimator(CommonTransitions.createEmpty());
    d.showPacked(BorderLayout.CENTER, false);
    return d;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog)

Example 47 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class InteractionDialog method show.

/**
 * This method shows the form as a modal alert allowing us to produce a behavior
 * of an alert/dialog box. This method will block the calling thread even if the
 * calling thread is the EDT. Notice that this method will not release the block
 * until dispose is called even if show() from another form is called!
 * <p>Modal dialogs Allow the forms "content" to "hang in mid air" this is especially useful for
 * dialogs where you would want the underlying form to "peek" from behind the
 * form.
 *
 * @param top space in pixels between the top of the screen and the form
 * @param bottom space in pixels between the bottom of the screen and the form
 * @param left space in pixels between the left of the screen and the form
 * @param right space in pixels between the right of the screen and the form
 */
public void show(int top, int bottom, int left, int right) {
    disposed = false;
    Form f = Display.getInstance().getCurrent();
    getUnselectedStyle().setMargin(TOP, top);
    getUnselectedStyle().setMargin(BOTTOM, bottom);
    getUnselectedStyle().setMargin(LEFT, left);
    getUnselectedStyle().setMargin(RIGHT, right);
    getUnselectedStyle().setMarginUnit(new byte[] { Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS });
    // might occur when showing the dialog twice...
    remove();
    getLayeredPane(f).addComponent(BorderLayout.center(this));
    if (animateShow) {
        int x = left + (f.getWidth() - right - left) / 2;
        int y = top + (f.getHeight() - bottom - top) / 2;
        if (repositionAnimation) {
            getParent().setX(x);
            getParent().setY(y);
            getParent().setWidth(1);
            getParent().setHeight(1);
        } else {
            getParent().setX(getX());
            getParent().setY(getY());
            setX(0);
            setY(0);
            getParent().setWidth(getWidth());
            getParent().setHeight(getHeight());
        }
        getLayeredPane(f).animateLayout(400);
    } else {
        getLayeredPane(f).revalidate();
    }
/*
        Form f = Display.getInstance().getCurrent();
        f.getLayeredPane().setLayout(new BorderLayout());
        getUnselectedStyle().setMargin(TOP, top);
        getUnselectedStyle().setMargin(BOTTOM, bottom);
        getUnselectedStyle().setMargin(LEFT, left);
        getUnselectedStyle().setMargin(RIGHT, right);
        getUnselectedStyle().setMarginUnit(new byte[] {Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS});
        f.getLayeredPane().addComponent(BorderLayout.CENTER, this);
        if(animateShow) {
            int x = left + (f.getWidth() - right - left) / 2;
            int y = top + (f.getHeight() - bottom - top) / 2;
            setX(x);
            setY(y);
            setWidth(1);
            setHeight(1);
            f.getLayeredPane().animateLayout(400);
        } else {
            f.getLayeredPane().revalidate();
        }
        */
}
Also used : Form(com.codename1.ui.Form)

Example 48 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class Tree method expandPathNode.

private Container expandPathNode(boolean animate, Container parent, Object node) {
    int cc = parent.getComponentCount();
    for (int iter = 0; iter < cc; iter++) {
        Component current = parent.getComponentAt(iter);
        Object o = current.getClientProperty(KEY_OBJECT);
        if (!model.isLeaf(o)) {
            // if(current instanceof Container) {
            BorderLayout bl = (BorderLayout) ((Container) current).getLayout();
            // the tree component is always at north expanded or otherwise
            current = bl.getNorth();
            if (o == node || o != null && o.equals(node)) {
                if (isExpanded(current)) {
                    return (Container) bl.getCenter();
                }
                return expandNodeImpl(animate, current);
            }
        }
    }
    return null;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Component(com.codename1.ui.Component)

Example 49 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout 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 50 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class JavaSEPort method init.

/**
 * @inheritDoc
 */
public void init(Object m) {
    inInit = true;
    File updater = new File(System.getProperty("user.home") + File.separator + ".codenameone" + File.separator + "UpdateCodenameOne.jar");
    if (!updater.exists()) {
        System.out.println("******************************************************************************");
        System.out.println("* It seems that you are using an old plugin version please upate to the latest plugin and invoke Codename One -> Codename One Settings -> Basic -> Update Client Libs");
        System.out.println("******************************************************************************");
    }
    Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
    boolean desktopSkin = pref.getBoolean("desktopSkin", false);
    if (desktopSkin && m == null) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        setDefaultPixelMilliRatio(tk.getScreenResolution() / 25.4 * getRetinaScale());
        pixelMilliRatio = getDefaultPixelMilliRatio();
        JPanel panel = new javax.swing.JPanel();
        panel.setLayout(new BorderLayout());
        JPanel bottom = new javax.swing.JPanel();
        panel.setOpaque(false);
        bottom.setLayout(new FlowLayout(FlowLayout.RIGHT));
        widthLabel = new JLabel("Width:   ");
        heightLabel = new JLabel(" Height:   ");
        bottom.add(widthLabel);
        bottom.add(heightLabel);
        panel.add(bottom, BorderLayout.SOUTH);
        JFrame frame = new JFrame();
        // frame.addWindowListener(new WindowListener() {
        // 
        // });
        frame.setLayout(new BorderLayout());
        frame.add(panel, BorderLayout.CENTER);
        frame.setSize(new Dimension(300, 400));
        m = panel;
        window = frame;
    }
    setInvokePointerHover(desktopSkin || invokePointerHover);
    // this is essential for push and other things to work in the simulator
    Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
    String user = p.get("user", null);
    if (user != null) {
        Display d = Display.getInstance();
        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);
        }
    }
    try {
        Class.forName("javafx.embed.swing.JFXPanel");
        Platform.setImplicitExit(false);
        fxExists = true;
    } catch (Throwable ex) {
    }
    String hide = System.getProperty("hideMenu", "false");
    if (hide != null && hide.equals("true")) {
        showMenu = false;
    }
    URLConnection.setDefaultAllowUserInteraction(true);
    HttpURLConnection.setFollowRedirects(false);
    if (!blockMonitors && pref.getBoolean("NetworkMonitor", false)) {
        showNetworkMonitor();
    }
    if (!blockMonitors && pref.getBoolean("PushSimulator", false)) {
        pushSimulation = new PushSimulator();
        pushSimulation.setVisible(true);
    }
    if (!blockMonitors && pref.getBoolean("PerformanceMonitor", false)) {
        showPerformanceMonitor();
    }
    if (defaultInitTarget != null && m == null) {
        m = defaultInitTarget;
    }
    if (canvas.getParent() != null) {
        canvas.getParent().remove(canvas);
    }
    if (m != null && m instanceof java.awt.Container) {
        java.awt.Container cnt = (java.awt.Container) m;
        if (cnt.getLayout() instanceof java.awt.BorderLayout) {
            cnt.add(java.awt.BorderLayout.CENTER, canvas);
        } else {
            cnt.add(canvas);
        }
    } else {
        window = new JFrame();
        window.setLayout(new java.awt.BorderLayout());
        hSelector = new JScrollBar(Scrollbar.HORIZONTAL);
        vSelector = new JScrollBar(Scrollbar.VERTICAL);
        hSelector.addAdjustmentListener(canvas);
        vSelector.addAdjustmentListener(canvas);
        scrollableSkin = pref.getBoolean("Scrollable", true);
        if (scrollableSkin) {
            window.add(java.awt.BorderLayout.SOUTH, hSelector);
            window.add(java.awt.BorderLayout.EAST, vSelector);
        }
        window.add(java.awt.BorderLayout.CENTER, canvas);
    }
    if (window != null) {
        java.awt.Image large = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/application64.png"));
        java.awt.Image small = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/application48.png"));
        try {
            // setIconImages is only available in JDK 1.6
            window.setIconImages(Arrays.asList(new java.awt.Image[] { large, small }));
        } catch (Throwable err) {
            window.setIconImage(small);
        }
        window.addWindowListener(new WindowListener() {

            public void windowOpened(WindowEvent e) {
            }

            public void windowClosing(WindowEvent e) {
                Display.getInstance().exitApplication();
            }

            public void windowClosed(WindowEvent e) {
            }

            public void windowIconified(WindowEvent e) {
            }

            public void windowDeiconified(WindowEvent e) {
            }

            public void windowActivated(WindowEvent e) {
            }

            public void windowDeactivated(WindowEvent e) {
            }
        });
        window.setLocationByPlatform(true);
        android6PermissionsFlag = pref.getBoolean("Android6Permissions", false);
        alwaysOnTop = pref.getBoolean("AlwaysOnTop", false);
        window.setAlwaysOnTop(alwaysOnTop);
        String reset = System.getProperty("resetSkins");
        if (reset != null && reset.equals("true")) {
            System.setProperty("resetSkins", "");
            pref = Preferences.userNodeForPackage(JavaSEPort.class);
            pref.put("skins", DEFAULT_SKINS);
        }
        if (hasSkins()) {
            if (m == null) {
                String f = System.getProperty("skin");
                if (f != null) {
                    loadSkinFile(f, window);
                } else {
                    String d = System.getProperty("dskin");
                    f = pref.get("skin", d);
                    loadSkinFile(f, window);
                }
            } else {
                try {
                    installMenu(window, true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else {
            Resources.setRuntimeMultiImageEnabled(true);
            window.setUndecorated(true);
            window.setExtendedState(JFrame.MAXIMIZED_BOTH);
        }
        window.pack();
        if (getSkin() != null && !scrollableSkin) {
            float w1 = ((float) canvas.getWidth() * (float) retinaScale) / ((float) getSkin().getWidth());
            float h1 = ((float) canvas.getHeight() * (float) retinaScale) / ((float) getSkin().getHeight());
            zoomLevel = Math.min(h1, w1);
        }
        portrait = pref.getBoolean("Portrait", true);
        if (!portrait && getSkin() != null) {
            canvas.setForcedSize(new java.awt.Dimension((int) (getSkin().getWidth() / retinaScale), (int) (getSkin().getHeight() / retinaScale)));
            window.setSize(new java.awt.Dimension((int) (getSkin().getWidth() / retinaScale), (int) (getSkin().getHeight() / retinaScale)));
        }
        window.setVisible(true);
    }
    if (useNativeInput) {
        Display.getInstance().setDefaultVirtualKeyboard(null);
    }
    float factor = ((float) getDisplayHeight()) / 480.0f;
    if (factor > 0 && autoAdjustFontSize && getSkin() != null) {
        // set a reasonable default font size
        setFontSize((int) (15.0f * factor), (int) (11.0f * factor), (int) (19.0f * factor));
    }
    if (m instanceof Runnable) {
        Display.getInstance().callSerially((Runnable) m);
    }
    inInit = false;
}
Also used : EncodedImage(com.codename1.ui.EncodedImage) Image(com.codename1.ui.Image) BufferedImage(java.awt.image.BufferedImage) JFrame(javax.swing.JFrame) Toolkit(java.awt.Toolkit) Preferences(java.util.prefs.Preferences) WindowListener(java.awt.event.WindowListener) Dimension(java.awt.Dimension) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) EOFException(java.io.EOFException) FontFormatException(java.awt.FontFormatException) Dimension(java.awt.Dimension) WindowEvent(java.awt.event.WindowEvent) Display(com.codename1.ui.Display) java.awt(java.awt)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)64 ActionEvent (com.codename1.ui.events.ActionEvent)27 Container (com.codename1.ui.Container)21 Form (com.codename1.ui.Form)18 ActionListener (com.codename1.ui.events.ActionListener)18 Component (com.codename1.ui.Component)15 BoxLayout (com.codename1.ui.layouts.BoxLayout)14 Label (com.codename1.ui.Label)12 Button (com.codename1.ui.Button)10 IOException (java.io.IOException)9 Dialog (com.codename1.ui.Dialog)8 Hashtable (java.util.Hashtable)8 Command (com.codename1.ui.Command)6 TextArea (com.codename1.ui.TextArea)6 FlowLayout (com.codename1.ui.layouts.FlowLayout)6 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Vector (java.util.Vector)6 RadioButton (com.codename1.ui.RadioButton)5 Animation (com.codename1.ui.animations.Animation)4 Style (com.codename1.ui.plaf.Style)4