001 // This file is part of the Attempto Java Packages. 002 // Copyright 2008, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch). 003 // 004 // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the 005 // terms of the GNU Lesser General Public License as published by the Free Software Foundation, 006 // either version 3 of the License, or (at your option) any later version. 007 // 008 // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY 009 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 // PURPOSE. See the GNU Lesser General Public License for more details. 011 // 012 // You should have received a copy of the GNU Lesser General Public License along with the Attempto 013 // Java Packages. If not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.preditor; 016 017 import nextapp.echo2.app.Extent; 018 import nextapp.echo2.app.Font; 019 import ch.uzh.ifi.attempto.echocomp.Style; 020 import ch.uzh.ifi.attempto.preditor.text.TextElement; 021 022 /** 023 * This class represents a menu item that contains a text element. The text element is added to 024 * the partial sentence when the user clicks on a menu entry in the predictive editor. 025 * 026 * @author Tobias Kuhn 027 */ 028 public class MenuEntry extends MenuItem { 029 030 private TextElement textElement; 031 private boolean strong = true; 032 private boolean highlighted = false; 033 034 /** 035 * Creates a new menu entry for the given text element. 036 * 037 * @param textElement The text element. 038 */ 039 public MenuEntry(TextElement textElement) { 040 this.textElement = textElement; 041 setText(textElement.getText()); 042 setFont(new Font(Style.fontTypeface, Font.PLAIN, new Extent(12))); 043 } 044 045 /** 046 * Returns the text element. 047 * 048 * @return The text element. 049 */ 050 public TextElement getTextElement() { 051 return textElement; 052 } 053 054 /** 055 * This method determines whether the menu entry is highlighted or not. Hightlighted menu entries 056 * are displayed in bold font and are in front of non-highlighted menu entries in sorted lists. 057 * 058 * @param highlighted 059 */ 060 public void setHighlighted(boolean highlighted) { 061 this.highlighted = highlighted; 062 if (highlighted) { 063 setFont(new Font(Style.fontTypeface, Font.BOLD, new Extent(12))); 064 } else { 065 setFont(new Font(Style.fontTypeface, Font.PLAIN, new Extent(12))); 066 } 067 } 068 069 public boolean equals(Object obj) { 070 if (obj instanceof MenuEntry) { 071 return textElement.equals(((MenuEntry) obj).textElement); 072 } 073 return false; 074 } 075 076 public int compareTo(MenuItem m) { 077 if (m instanceof MenuEntry) { 078 MenuEntry other = (MenuEntry) m; 079 if (this.strong && !other.strong) { 080 return -1; 081 } else if (!this.strong && other.strong) { 082 return 1; 083 } else { 084 if (this.highlighted && !other.highlighted) { 085 return -1; 086 } else if (!this.highlighted && other.highlighted) { 087 return 1; 088 } else { 089 return super.compareTo(m); 090 } 091 } 092 } else { 093 return super.compareTo(m); 094 } 095 } 096 097 }