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 nextapp.echo.app.event.ActionListener;
020 import ch.uzh.ifi.attempto.echocomp.Style;
021
022 /**
023 * This abstract class represents a menu item that performs an action when the user clicks on it.
024 *
025 * @author Tobias Kuhn
026 */
027 public class SpecialMenuItem extends MenuItem {
028
029 private static final long serialVersionUID = -2762672905600512854L;
030
031 /**
032 * Creates a new special menu item.
033 *
034 * @param text The text of the menu item.
035 * @param menuGroup The menu group to which this item should be assigned.
036 * @param actionCommand The action command.
037 * @param actionListener The action listener.
038 */
039 public SpecialMenuItem(String text, String menuGroup, String actionCommand, ActionListener actionListener) {
040 super(menuGroup);
041 if (text == null) text = "";
042 setText(text);
043 if (actionCommand == null) actionCommand = "";
044 setActionCommand(actionCommand);
045 setForeground(Style.mediumForeground);
046 if (actionListener != null) {
047 addActionListener(actionListener);
048 }
049 updateStyle();
050 }
051
052 /**
053 * Creates a new special menu item.
054 *
055 * @param text The text of the menu item.
056 * @param menuGroup The menu group to which this item should be assigned.
057 * @param actionCommand The action command.
058 */
059 public SpecialMenuItem(String text, String menuGroup, String actionCommand) {
060 this(text, menuGroup, actionCommand, null);
061 }
062
063 /**
064 * Creates a new special menu item.
065 *
066 * @param text The text of the menu item.
067 * @param menuGroup The menu group to which this item should be assigned.
068 */
069 public SpecialMenuItem(String text, String menuGroup) {
070 this(text, menuGroup, text, null);
071 }
072
073 /**
074 * Creates a new special menu item.
075 *
076 * @param text The text of the menu item.
077 */
078 public SpecialMenuItem(String text) {
079 this(text, "", text, null);
080 }
081
082 protected void updateStyle() {
083 if (isHighlighted()) {
084 setFont(new Font(Style.fontTypeface, Font.BOLD, new Extent(12)));
085 } else {
086 setFont(new Font(Style.fontTypeface, Font.PLAIN, new Extent(12)));
087 }
088 }
089
090 protected String[] getContent() {
091 return new String[] {"special", getText(), getMenuGroup(), getActionCommand()};
092 }
093
094 }