Search in sources :

Example 66 with List

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

the class DefaultLookAndFeel method getListPreferredSizeImpl.

private Dimension getListPreferredSizeImpl(List l) {
    int width = 0;
    int height = 0;
    int selectedHeight;
    int selectedWidth;
    ListModel model = l.getModel();
    int numOfcomponents = Math.max(model.getSize(), l.getMinElementHeight());
    numOfcomponents = Math.min(numOfcomponents, l.getMaxElementHeight());
    Object prototype = l.getRenderingPrototype();
    Style unselectedEntryStyle = null;
    Style selectedEntryStyle;
    if (prototype != null) {
        ListCellRenderer renderer = l.getRenderer();
        Component cmp = renderer.getListCellRendererComponent(l, prototype, 0, false);
        height = cmp.getPreferredH();
        width = cmp.getPreferredW();
        unselectedEntryStyle = cmp.getStyle();
        cmp = renderer.getListCellRendererComponent(l, prototype, 0, true);
        selectedEntryStyle = cmp.getStyle();
        selectedHeight = Math.max(height, cmp.getPreferredH());
        selectedWidth = Math.max(width, cmp.getPreferredW());
    } else {
        int hightCalcComponents = Math.min(l.getListSizeCalculationSampleCount(), numOfcomponents);
        Object dummyProto = l.getRenderingPrototype();
        if (model.getSize() > 0 && dummyProto == null) {
            dummyProto = model.getItemAt(0);
        }
        ListCellRenderer renderer = l.getRenderer();
        for (int i = 0; i < hightCalcComponents; i++) {
            Object value;
            if (i < model.getSize()) {
                value = model.getItemAt(i);
            } else {
                value = dummyProto;
            }
            Component cmp = renderer.getListCellRendererComponent(l, value, i, false);
            if (cmp instanceof Container) {
                cmp.setShouldCalcPreferredSize(true);
            }
            unselectedEntryStyle = cmp.getStyle();
            height = Math.max(height, cmp.getPreferredH());
            width = Math.max(width, cmp.getPreferredW());
        }
        selectedEntryStyle = unselectedEntryStyle;
        selectedHeight = height;
        selectedWidth = width;
        if (model.getSize() > 0) {
            Object value = model.getItemAt(0);
            Component cmp = renderer.getListCellRendererComponent(l, value, 0, true);
            if (cmp instanceof Container) {
                cmp.setShouldCalcPreferredSize(true);
            }
            selectedHeight = Math.max(height, cmp.getPreferredH());
            selectedWidth = Math.max(width, cmp.getPreferredW());
            selectedEntryStyle = cmp.getStyle();
        }
    }
    if (unselectedEntryStyle != null) {
        selectedWidth += selectedEntryStyle.getMarginLeftNoRTL() + selectedEntryStyle.getMarginRightNoRTL();
        selectedHeight += selectedEntryStyle.getMarginTop() + selectedEntryStyle.getMarginBottom();
        width += unselectedEntryStyle.getMarginLeftNoRTL() + unselectedEntryStyle.getMarginRightNoRTL();
        height += unselectedEntryStyle.getMarginTop() + unselectedEntryStyle.getMarginBottom();
    }
    Style lStyle = l.getStyle();
    int verticalPadding = lStyle.getPaddingTop() + lStyle.getPaddingBottom();
    int horizontalPadding = lStyle.getPaddingRightNoRTL() + lStyle.getPaddingLeftNoRTL() + l.getSideGap();
    if (numOfcomponents == 0) {
        return new Dimension(horizontalPadding, verticalPadding);
    }
    // If combobox without ever importing the ComboBox class dependency
    if (l.getOrientation() > List.HORIZONTAL) {
        int boxWidth = l.getStyle().getFont().getHeight() + 2;
        return new Dimension(boxWidth + selectedWidth + horizontalPadding, selectedHeight + verticalPadding);
    } else {
        if (l.getOrientation() == List.VERTICAL) {
            return new Dimension(selectedWidth + horizontalPadding, selectedHeight + (height + l.getItemGap()) * (numOfcomponents - 1) + verticalPadding);
        } else {
            return new Dimension(selectedWidth + (width + l.getItemGap()) * (numOfcomponents - 1) + horizontalPadding, selectedHeight + verticalPadding);
        }
    }
}
Also used : Container(com.codename1.ui.Container) ListModel(com.codename1.ui.list.ListModel) ListCellRenderer(com.codename1.ui.list.ListCellRenderer) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 67 with List

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

the class UserInterfaceEditor method reflowTableLayout.

private void reflowTableLayout(com.codename1.ui.Container parent) {
    // affects the layout initially
    if (parent.getLayout() instanceof com.codename1.ui.table.TableLayout) {
        List<com.codename1.ui.Component> cmpList = new ArrayList<com.codename1.ui.Component>();
        List constraintList = new ArrayList();
        for (int iter = 0; iter < parent.getComponentCount(); iter++) {
            com.codename1.ui.Component currentCmp = parent.getComponentAt(iter);
            cmpList.add(currentCmp);
            constraintList.add(parent.getLayout().getComponentConstraint(currentCmp));
        }
        parent.removeAll();
        for (int iter = 0; iter < cmpList.size(); iter++) {
            parent.addComponent(constraintList.get(iter), cmpList.get(iter));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JList(javax.swing.JList) Component(java.awt.Component) JComponent(javax.swing.JComponent) TableLayout(com.codename1.ui.table.TableLayout) Point(java.awt.Point)

Example 68 with List

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

the class UserInterfaceEditor method getListOfAllCommands.

private static List<com.codename1.ui.Command> getListOfAllCommands(EditableResources res) {
    final List<com.codename1.ui.Command> response = new ArrayList<com.codename1.ui.Command>();
    UIBuilderOverride tempBuilder = new UIBuilderOverride() {

        public com.codename1.ui.Command createCommandImpl(String commandName, com.codename1.ui.Image icon, int commandId, String action, boolean isBack, String arg) {
            com.codename1.ui.Command c = super.createCommandImpl(commandName, icon, commandId, action, isBack, arg);
            if (!response.contains(c)) {
                response.add(c);
            }
            return c;
        }
    };
    for (String uiResourceName : res.getUIResourceNames()) {
        tempBuilder.createContainer(res, uiResourceName);
    }
    Collections.sort(response, new Comparator<com.codename1.ui.Command>() {

        public int compare(com.codename1.ui.Command o1, com.codename1.ui.Command o2) {
            if (o1 == null) {
                if (o2 == null) {
                    return 0;
                }
                return -1;
            }
            if (o2 == null) {
                return 1;
            }
            return String.CASE_INSENSITIVE_ORDER.compare(o1.getCommandName(), o2.getCommandName());
        }
    });
    return response;
}
Also used : Command(com.codename1.ui.Command) UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride) Command(com.codename1.ui.Command) ArrayList(java.util.ArrayList)

Example 69 with List

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

the class EditableResources method saveL10N.

private void saveL10N(DataOutputStream output, Hashtable l10n) throws IOException {
    List keys = new ArrayList();
    for (Object locale : l10n.keySet()) {
        Hashtable current = (Hashtable) l10n.get(locale);
        for (Object key : current.keySet()) {
            if (!keys.contains(key)) {
                keys.add(key);
            }
        }
    }
    output.writeShort(keys.size());
    output.writeShort(l10n.size());
    for (Object key : keys) {
        output.writeUTF((String) key);
    }
    for (Object locale : l10n.keySet()) {
        Hashtable currentLanguage = (Hashtable) l10n.get(locale);
        output.writeUTF((String) locale);
        for (Object key : keys) {
            String k = (String) currentLanguage.get(key);
            if (k != null) {
                output.writeUTF(k);
            } else {
                output.writeUTF("");
            }
        }
    }
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AnimationObject(com.codename1.ui.animations.AnimationObject)

Example 70 with List

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

the class JavaSEPort method openInputStream.

/**
 * @inheritDoc
 */
public InputStream openInputStream(Object connection) throws IOException {
    if (connection instanceof String) {
        FileInputStream fc = new FileInputStream(unfile((String) connection));
        BufferedInputStream o = new BufferedInputStream(fc, (String) connection);
        return o;
    }
    if (netMonitor != null || slowConnectionMode || disconnectedMode) {
        final NetworkRequestObject nr = getByConnection((URLConnection) connection);
        if (nr != null || slowConnectionMode || disconnectedMode) {
            if (slowConnectionMode) {
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                }
            }
            if (disconnectedMode) {
                throw new IOException("Unreachable");
            }
            HttpURLConnection con = (HttpURLConnection) connection;
            String headers = "";
            Map<String, List<String>> map = con.getHeaderFields();
            for (String header : map.keySet()) {
                headers += header + "=" + map.get(header) + "\n";
            }
            if (nr != null) {
                nr.setResponseHeaders(headers);
                nr.setResponseBody("");
            }
            InputStream is;
            if (con.getResponseCode() >= 200 && con.getResponseCode() < 300) {
                is = con.getInputStream();
            } else {
                is = con.getErrorStream();
            }
            InputStream i = new BufferedInputStream(is) {

                public synchronized int read(byte[] b, int off, int len) throws IOException {
                    int s = super.read(b, off, len);
                    if (nr != null) {
                        if (s > -1) {
                            nr.setResponseBody(nr.getResponseBody() + new String(b, off, len));
                        }
                    }
                    if (slowConnectionMode) {
                        try {
                            Thread.sleep(len);
                        } catch (Exception e) {
                        }
                    }
                    if (disconnectedMode) {
                        throw new IOException("Unreachable");
                    }
                    return s;
                }
            };
            return i;
        }
    }
    if (connection instanceof HttpURLConnection) {
        HttpURLConnection ht = (HttpURLConnection) connection;
        if (ht.getResponseCode() < 400) {
            return new BufferedInputStream(ht.getInputStream());
        }
        return new BufferedInputStream(ht.getErrorStream());
    } else {
        return new BufferedInputStream(((URLConnection) connection).getInputStream());
    }
}
Also used : BufferedInputStream(com.codename1.io.BufferedInputStream) BufferedInputStream(com.codename1.io.BufferedInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) List(java.util.List) NodeList(org.w3c.dom.NodeList) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) EOFException(java.io.EOFException) FontFormatException(java.awt.FontFormatException) Point(java.awt.Point)

Aggregations

Paint (com.codename1.charts.compat.Paint)26 ArrayList (java.util.ArrayList)24 Component (com.codename1.ui.Component)16 List (com.codename1.ui.List)13 Point (com.codename1.charts.models.Point)11 BorderLayout (com.codename1.ui.layouts.BorderLayout)11 Hashtable (java.util.Hashtable)11 Container (com.codename1.ui.Container)9 ContainerList (com.codename1.ui.list.ContainerList)9 Button (com.codename1.ui.Button)8 List (java.util.List)8 TextArea (com.codename1.ui.TextArea)7 Dimension (com.codename1.ui.geom.Dimension)7 EncodedImage (com.codename1.ui.EncodedImage)6 Label (com.codename1.ui.Label)6 RadioButton (com.codename1.ui.RadioButton)5 ActionListener (com.codename1.ui.events.ActionListener)5 JList (javax.swing.JList)4 FileEncodedImage (com.codename1.components.FileEncodedImage)3 StorageImage (com.codename1.components.StorageImage)3