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.preditor;
016
017 import nextapp.echo.app.Extent;
018 import nextapp.echo.app.Font;
019 import ch.uzh.ifi.attempto.base.ConcreteOption;
020 import ch.uzh.ifi.attempto.base.TextElement;
021 import ch.uzh.ifi.attempto.echocomp.Style;
022
023 /**
024 * This class represents a menu item that contains a text element. The text element is added to
025 * the partial sentence when the user clicks on a menu entry in the predictive editor.
026 *
027 * @author Tobias Kuhn
028 */
029 public class MenuEntry extends MenuItem {
030
031 private static final long serialVersionUID = -4231372412315340523L;
032
033 private TextElement textElement;
034
035 /**
036 * Creates a new menu entry for the given word.
037 *
038 * @param word The word.
039 * @param menuGroup The menu group to which this entry should be assigned.
040 */
041 public MenuEntry(String word, String menuGroup) {
042 this(new TextElement(word), menuGroup);
043 }
044
045 /**
046 * Creates a new menu entry on the basis of the given text element.
047 *
048 * @param textElement The text element.
049 * @param menuGroup The menu group to which this entry should be assigned.
050 */
051 public MenuEntry(TextElement textElement, String menuGroup) {
052 super(menuGroup);
053 this.textElement = textElement;
054 setText(textElement.getText());
055 setFont(new Font(Style.fontTypeface, Font.PLAIN, new Extent(12)));
056 }
057
058 /**
059 * Creates a new menu entry on the basis of the given concrete option.
060 *
061 * @param cOption The concrete option.
062 * @param menuGroup The menu group to which this entry should be assigned.
063 */
064 public MenuEntry(ConcreteOption cOption, String menuGroup) {
065 this(cOption.getWord(), menuGroup);
066 }
067
068 /**
069 * Returns the text element.
070 *
071 * @return The text element.
072 */
073 public TextElement getTextElement() {
074 return textElement;
075 }
076
077 protected String[] getContent() {
078 return new String[] {"entry", getText(), getMenuGroup()};
079 }
080
081 }