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.SolidLabel;
018    import nextapp.echo.app.Border;
019    import nextapp.echo.app.Color;
020    import nextapp.echo.app.Column;
021    import nextapp.echo.app.Font;
022    import nextapp.echo.app.Grid;
023    import nextapp.echo.app.Insets;
024    
025    /**
026     * This class represents a graphical table that displays simple name/value pairs.
027     * 
028     * @author Tobias Kuhn
029     */
030    public class NameValueTable extends Column {
031    
032            private static final long serialVersionUID = -5329037871133296963L;
033            
034            private Grid grid;
035            
036            /**
037             * Creates a new table.
038             */
039            public NameValueTable() {
040                    grid = new Grid(2);
041                    grid.setInsets(new Insets(5, 1, 20, 2));
042                    grid.setBorder(new Border(1, Color.DARKGRAY, Border.STYLE_SOLID));
043                    grid.setBackground(new Color(240, 240, 240));
044                    add(grid);
045            }
046            
047            /**
048             * Adds the name/value pair to the table. The value is displayed in italics.
049             * 
050             * @param name The name.
051             * @param value The value.
052             */
053            public void addEntry(String name, String value) {
054                    grid.add(new SolidLabel(name, Font.ITALIC + Font.BOLD, 11));
055                    grid.add(new SolidLabel(value, Font.ITALIC));
056            }
057            
058            /**
059             * Adds the name/value pair to the table. The value is supposed to be an ACE phrase and is for
060             * that reason displayed in normal font (non-italics).
061             * 
062             * @param name The name.
063             * @param aceValue The ACE phrase as value.
064             */
065            public void addACEEntry(String name, String aceValue) {
066                    grid.add(new SolidLabel(name, Font.ITALIC + Font.BOLD, 11));
067                    grid.add(new SolidLabel(aceValue));
068            }
069            
070            /**
071             * Removes all entries.
072             */
073            public void clear() {
074                    grid.removeAll();
075            }
076    
077    }