001    // This file is part of AceWiki.
002    // Copyright 2008-2012, AceWiki developers.
003    // 
004    // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005    // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006    // the License, or (at your option) any later version.
007    // 
008    // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009    // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010    // Lesser General Public License for more details.
011    // 
012    // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013    // not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.acewiki.gui;
016    
017    import ch.uzh.ifi.attempto.echocomp.Label;
018    import nextapp.echo.app.Alignment;
019    import nextapp.echo.app.Column;
020    import nextapp.echo.app.Component;
021    import nextapp.echo.app.Extent;
022    import nextapp.echo.app.Font;
023    import nextapp.echo.app.Row;
024    import nextapp.echo.app.layout.RowLayoutData;
025    
026    /**
027     * This class represents a GUI component that is shown as a list item with a preceding "-".
028     * 
029     * @author Tobias Kuhn
030     */
031    public class ListItem extends Row {
032            
033            private static final long serialVersionUID = 1214629285195105570L;
034    
035            /**
036             * Creates a new list item that contains the given components.
037             * 
038             * @param components The components of the list item.
039             */
040            public ListItem(Component... components) {
041                    setCellSpacing(new Extent(2));
042                    Label l = new Label("-", Font.PLAIN, 11);
043                    RowLayoutData layout = new RowLayoutData();
044                    layout.setAlignment(new Alignment(Alignment.LEFT, Alignment.TOP));
045                    l.setLayoutData(layout);
046                    add(l);
047                    if (components.length == 1) {
048                            add(components[0]);
049                    } else {
050                            Column col = new Column();
051                            col.setCellSpacing(new Extent(2));
052                            Row row = new Row();
053                            for (Component c : components) {
054                                    if (c == null) {
055                                            col.add(row);
056                                            row = new Row();
057                                    } else {
058                                            row.add(c);
059                                    }
060                                    col.add(row);
061                                    add(col);
062                            }
063                    }
064            }
065    
066    }