Search in sources :

Example 86 with com.codename1.io

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

the class AutoCompleteTextField method addPopup.

private void addPopup(boolean updateFilter) {
    final Form f = getComponentForm();
    popup.removeAll();
    popup.setVisible(false);
    popup.setEnabled(false);
    if (updateFilter) {
        filter(getText());
    }
    final com.codename1.ui.List l = new com.codename1.ui.List(getSuggestionModel());
    if (getMinimumElementsShownInPopup() > 0) {
        l.setMinElementHeight(getMinimumElementsShownInPopup());
    }
    l.setScrollToSelected(false);
    l.setItemGap(0);
    for (ActionListener al : listeners) {
        l.addActionListener(al);
    }
    if (completionRenderer == null) {
        ((DefaultListCellRenderer<String>) l.getRenderer()).setShowNumbers(false);
    } else {
        l.setRenderer(completionRenderer);
    }
    l.setUIID("AutoCompleteList");
    l.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (shouldShowPopup()) {
                pickedText = (String) l.getSelectedItem();
                setParentText(pickedText);
                fireActionEvent();
                // relaunch text editing if we are still editing
                if (Display.getInstance().isTextEditing(AutoCompleteTextField.this)) {
                    Display.getInstance().editString(AutoCompleteTextField.this, getMaxSize(), getConstraint(), (String) l.getSelectedItem());
                }
                popup.setVisible(false);
                popup.setEnabled(false);
                f.revalidate();
            }
        }
    });
    byte[] units = popup.getStyle().getMarginUnit();
    if (units != null) {
        units[Component.LEFT] = Style.UNIT_TYPE_PIXELS;
        units[Component.TOP] = Style.UNIT_TYPE_PIXELS;
        popup.getAllStyles().setMarginUnit(units);
    }
    int leftMargin = isRTL() ? Math.max(0, f.getWidth() - getAbsoluteX() - getWidth()) : Math.max(0, getAbsoluteX());
    popup.getAllStyles().setMargin(LEFT, leftMargin);
    int popupHeight = calcPopupHeight(l);
    popup.setPreferredW(getWidth());
    popup.setHeight(popupHeight);
    popup.setWidth(getWidth());
    popup.addComponent(l);
    popup.layoutContainer();
    // block the reflow of this popup, which can cause painting problems
    dontCalcSize = true;
    if (f != null) {
        if (popup.getParent() == null) {
            Container lay = f.getLayeredPane(AutoCompleteTextField.this.getClass(), true);
            lay.setLayout(new LayeredLayout());
            Container wrapper = new Container();
            wrapper.add(popup);
            lay.addComponent(wrapper);
        }
        f.revalidate();
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) ActionListener(com.codename1.ui.events.ActionListener) ArrayList(java.util.ArrayList) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 87 with com.codename1.io

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

the class ThemeEditor method initMIDlet.

private void initMIDlet() {
    JavaSEPortWithSVGSupport.setShowEDTWarnings(false);
    JavaSEPortWithSVGSupport.setShowEDTViolationStacks(false);
    // its a UI form
    if (uiPreviewContent.getSelectedIndex() == uiPreviewContent.getModel().getSize() - 1) {
        previewPanel.removeAll();
        if (com.codename1.ui.Display.isInitialized()) {
            com.codename1.ui.Display.deinitialize();
        }
        JavaSEPortWithSVGSupport.setDefaultInitTarget(previewPanel);
        com.codename1.ui.Display.init(previewPanel);
        previewPanel.getComponent(0).setBounds(0, 0, get(widthResoltution), get(heightResolution));
        previewPanel.getComponent(0).setPreferredSize(new java.awt.Dimension(get(widthResoltution), get(heightResolution)));
        PickMIDlet.startMIDlet(themeHash);
    } else {
        Preferences.userNodeForPackage(getClass()).put("uiPreviewContent", (String) uiPreviewContent.getSelectedItem());
        Accessor.setTheme(themeHash);
        if (com.codename1.ui.Display.isInitialized()) {
            com.codename1.ui.Display.deinitialize();
        }
        previewPanel.removeAll();
        com.codename1.ui.Display.init(previewPanel);
        previewPanel.getComponent(0).setBounds(0, 0, get(widthResoltution), get(heightResolution));
        previewPanel.getComponent(0).setPreferredSize(new java.awt.Dimension(get(widthResoltution), get(heightResolution)));
        com.codename1.ui.util.UIBuilder.registerCustomComponent("Table", com.codename1.ui.table.Table.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("MediaPlayer", com.codename1.components.MediaPlayer.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("ContainerList", com.codename1.ui.list.ContainerList.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("ComponentGroup", com.codename1.ui.ComponentGroup.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("Tree", com.codename1.ui.tree.Tree.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("HTMLComponent", com.codename1.ui.html.HTMLComponent.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("RSSReader", com.codename1.components.RSSReader.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("FileTree", com.codename1.components.FileTree.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("WebBrowser", com.codename1.components.WebBrowser.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("NumericSpinner", com.codename1.ui.spinner.NumericSpinner.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("DateSpinner", com.codename1.ui.spinner.DateSpinner.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("TimeSpinner", com.codename1.ui.spinner.TimeSpinner.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("DateTimeSpinner", com.codename1.ui.spinner.DateTimeSpinner.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("GenericSpinner", com.codename1.ui.spinner.GenericSpinner.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("LikeButton", com.codename1.facebook.ui.LikeButton.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("InfiniteProgress", com.codename1.components.InfiniteProgress.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("MultiButton", com.codename1.components.MultiButton.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("SpanButton", com.codename1.components.SpanButton.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("SpanLabel", com.codename1.components.SpanLabel.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("Ads", com.codename1.components.Ads.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("MapComponent", com.codename1.maps.MapComponent.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("MultiList", com.codename1.ui.list.MultiList.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("ShareButton", com.codename1.components.ShareButton.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("OnOffSwitch", com.codename1.components.OnOffSwitch.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("ImageViewer", com.codename1.components.ImageViewer.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("AutoCompleteTextField", com.codename1.ui.AutoCompleteTextField.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("Picker", com.codename1.ui.spinner.Picker.class);
        Display.getInstance().callSerially(new Runnable() {

            @Override
            public void run() {
                com.codename1.ui.util.UIBuilder builder = new com.codename1.ui.util.UIBuilder();
                final com.codename1.ui.Container c = builder.createContainer(resources, (String) uiPreviewContent.getSelectedItem());
                if (c instanceof com.codename1.ui.Form) {
                    if (c instanceof com.codename1.ui.Dialog) {
                        com.codename1.ui.animations.Transition t = ((com.codename1.ui.Dialog) c).getTransitionInAnimator();
                        ((com.codename1.ui.Dialog) c).setTransitionInAnimator(com.codename1.ui.animations.CommonTransitions.createEmpty());
                        ((com.codename1.ui.Dialog) c).showModeless();
                        ((com.codename1.ui.Dialog) c).setTransitionInAnimator(t);
                    } else {
                        com.codename1.ui.animations.Transition t = ((com.codename1.ui.Form) c).getTransitionInAnimator();
                        ((com.codename1.ui.Form) c).setTransitionInAnimator(com.codename1.ui.animations.CommonTransitions.createEmpty());
                        ((com.codename1.ui.Form) c).show();
                        ((com.codename1.ui.Form) c).setTransitionInAnimator(t);
                    }
                } else {
                    com.codename1.ui.Form f = new Form();
                    f.setTransitionInAnimator(com.codename1.ui.animations.CommonTransitions.createEmpty());
                    f.setLayout(new com.codename1.ui.layouts.BorderLayout());
                    f.addComponent(com.codename1.ui.layouts.BorderLayout.CENTER, c);
                    f.show();
                }
            }
        });
    }
}
Also used : Form(com.codename1.ui.Form) Form(com.codename1.ui.Form) UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride) Hashtable(java.util.Hashtable)

Example 88 with com.codename1.io

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

the class ThemeEditor method findFlushingPropertyContrust.

/**
 * Returns a "contrasting" value for the property to flash, e.g. for a font,
 * return a differnet font or for a color return a ligher/darker color...
 */
private Object findFlushingPropertyContrust() {
    if (flashingProperty.indexOf("Color") > -1) {
        // flash to white or black depending on whether the color is closer to white
        int val = Integer.decode("0x" + originalFlashingPropertyValue);
        if (val > 0xf0f0f0) {
            return "000000";
        } else {
            return "ffffff";
        }
    }
    if (flashingProperty.indexOf("derive") > -1) {
        return "NoPropertyUIIDExists";
    }
    if (flashingProperty.indexOf("font") > -1) {
        // if this is not a bold font then just return a system bold font
        if ((((com.codename1.ui.Font) originalFlashingPropertyValue).getStyle() & com.codename1.ui.Font.STYLE_BOLD) != 0) {
            return com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN, com.codename1.ui.Font.SIZE_LARGE);
        }
        return com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_BOLD, com.codename1.ui.Font.SIZE_LARGE);
    }
    if (flashingProperty.indexOf("bgImage") > -1) {
        com.codename1.ui.Image i = (com.codename1.ui.Image) originalFlashingPropertyValue;
        return i.modifyAlpha((byte) 128);
    }
    if (flashingProperty.indexOf("transparency") > -1) {
        int v = Integer.parseInt((String) originalFlashingPropertyValue);
        if (v < 128) {
            return "255";
        } else {
            return "100";
        }
    }
    /*
         * if(flashingProperty.indexOf("scale") > -1) { return "false"; }
         */
    if (flashingProperty.indexOf("padding") > -1 || flashingProperty.indexOf("margin") > -1) {
        return "10,10,10,10";
    }
    if (flashingProperty.indexOf("border") > -1) {
        if (originalFlashingPropertyValue != null) {
            Border pressed = ((Border) originalFlashingPropertyValue).createPressedVersion();
            if (pressed != null) {
                return pressed;
            }
        }
        return Border.createBevelRaised();
    }
    if (flashingProperty.indexOf("bgType") > -1) {
        return originalFlashingPropertyValue;
    }
    if (flashingProperty.indexOf("bgGradient") > -1) {
        Object[] gradient = new Object[4];
        System.arraycopy(originalFlashingPropertyValue, 0, gradient, 0, 4);
        gradient[0] = ((Object[]) originalFlashingPropertyValue)[1];
        gradient[1] = ((Object[]) originalFlashingPropertyValue)[0];
        return gradient;
    }
    if (flashingProperty.indexOf("align") > -1 || flashingProperty.indexOf("textDecoration") > -1) {
        return originalFlashingPropertyValue;
    }
    throw new IllegalArgumentException("Unsupported property type: " + flashingProperty);
}
Also used : BufferedImage(java.awt.image.BufferedImage) Border(com.codename1.ui.plaf.Border)

Example 89 with com.codename1.io

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

the class TimelineEditor method cloneCurrentTimeline.

// </editor-fold>//GEN-END:initComponents
private Timeline cloneCurrentTimeline() {
    Timeline t = (Timeline) res.getImage(name);
    AnimationObject[] arr = new AnimationObject[t.getAnimationCount()];
    for (int iter = 0; iter < arr.length; iter++) {
        arr[iter] = t.getAnimation(iter);
    }
    Timeline nt = Timeline.createTimeline(getValue(duration), arr, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
    nt.setPause(t.isPause());
    nt.setTime(t.getTime());
    return nt;
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Point(java.awt.Point)

Example 90 with com.codename1.io

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

the class TimelineEditor method moveUpActionPerformed.

// GEN-LAST:event_duplicateObjectActionPerformed
private void moveUpActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_moveUpActionPerformed
    int i = animationObjectList.getSelectedRow();
    Timeline t = cloneCurrentTimeline();
    AnimationObject[] animations = new AnimationObject[t.getAnimationCount()];
    for (int iter = 0; iter < animations.length; iter++) {
        animations[iter] = t.getAnimation(iter);
    }
    AnimationObject o = animations[i - 1];
    animations[i - 1] = animations[i];
    animations[i] = o;
    Timeline nt = Timeline.createTimeline(getValue(duration), animations, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
    nt.setPause(t.isPause());
    setImage(nt);
    moveUp.setEnabled(i > 1);
    moveDown.setEnabled(true);
    animationObjectList.getSelectionModel().setSelectionInterval(i - 1, i - 1);
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Point(java.awt.Point)

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