    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.acewiki.gui;
    016
    017    import ch.uzh.ifi.attempto.echocomp.Style;
    018    import nextapp.echo2.app.Alignment;
    019    import nextapp.echo2.app.Border;
    020    import nextapp.echo2.app.Button;
    021    import nextapp.echo2.app.Color;
    022    import nextapp.echo2.app.Column;
    023    import nextapp.echo2.app.Extent;
    024    import nextapp.echo2.app.Font;
    025    import nextapp.echo2.app.Insets;
    026    import nextapp.echo2.app.ResourceImageReference;
    027    import nextapp.echo2.app.event.ActionEvent;
    028    import nextapp.echo2.app.event.ActionListener;
    029    import echopointng.DropDown;
    030
    031    /**
    032     * This class represents drop down menus that are shown in front of the ACE sentences as
    033     * small triangles.
    034     *
    035     * @author Tobias Kuhn
    036     */
    037    public class DropDownMenu extends DropDown implements ActionListener {
    038
    039            private static final long serialVersionUID = 3646511994109953476L;
    040
    041            private Column menuColumn = new Column();
    042            private ActionListener actionListener;
    043            private Column menuSeparator = null;
    044
    045            /**
    046             * Creates a empty drop down menu with an icon of the given color.
    047             *
    048             * @param color The color of the icon, one of "blue", "light-blue", or "red".
    049             * @param actionListener The actionlistener.
    050             */
    051            public DropDownMenu(String color, ActionListener actionListener) {
    052                    this.actionListener = actionListener;
    053                    setWidth(new Extent(13));
    054                    setPopUp(menuColumn);
    055                    setPopUpBorder(new Border(1, Color.BLACK, Border.STYLE_OUTSET));
    056                    setPopUpAlignment(new Alignment(Alignment.RIGHT, Alignment.BOTTOM));
    057                    setPopUpInsets(new Insets(0, 0));
    058                    setPopUpOutsets(new Insets(15, -15, 0, 0));
    059                    String img1 = null;
    060                    String img2 = null;
    061                    if (color.equals("blue")) {
    062                            img1 = "ch/uzh/ifi/attempto/acewiki/gui/img/DropDown1.png";
    063                            img2 = "ch/uzh/ifi/attempto/acewiki/gui/img/DropDown2.png";
    064                    } else if (color.equals("red")) {
    065                            img1 = "ch/uzh/ifi/attempto/acewiki/gui/img/DropDownRed1.png";
    066                            img2 = "ch/uzh/ifi/attempto/acewiki/gui/img/DropDownRed2.png";
    067                    } else if (color.equals("light-blue")) {
    068                            img1 = "ch/uzh/ifi/attempto/acewiki/gui/img/DropDownLBlue1.png";
    069                            img2 = "ch/uzh/ifi/attempto/acewiki/gui/img/DropDownLBlue2.png";
    070                    }
    071                    setToggleIcon(new ResourceImageReference(img1));
    072                    setToggleRolloverIcon(new ResourceImageReference(img2));
    073                    setTogglePressedIcon(new ResourceImageReference(img2));
    074                    setBorder(new Border(0, Color.BLACK, Border.STYLE_SOLID));
    075                    setRolloverBorder(new Border(0, Color.BLACK, Border.STYLE_SOLID));
    076            }
    077
    078            /**
    079             * Adds a menu entry to the drop down menu.
    080             *
    081             * @param text The text of the menu entry.
    082             */
    083            public void addMenuEntry(String text) {
    084                    if (menuSeparator != null) {
    085                            menuColumn.add(menuSeparator);
    086                            menuSeparator = null;
    087                    }
    088                    Button menuEntry = new Button(text);
    089                    menuEntry.setActionCommand(text);
    090                    menuEntry.setHeight(new Extent(16));
    091                    menuEntry.setWidth(new Extent(130));
    092                    menuEntry.setBackground(Style.mediumBackground);
    093                    menuEntry.setForeground(Style.darkForeground);
    094                    menuEntry.setRolloverEnabled(true);
    095                    menuEntry.setRolloverForeground(Style.lightForeground);
    096                    menuEntry.setRolloverBackground(Style.darkBackground);
    097                    menuEntry.setInsets(new Insets(2, 0));
    098                    menuEntry.setAlignment(new Alignment(Alignment.LEFT, Alignment.CENTER));
    099                    menuEntry.setTextAlignment(new Alignment(Alignment.LEFT, Alignment.CENTER));
    100                    menuEntry.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13)));
    101                    menuEntry.addActionListener(this);
    102                    menuColumn.add(menuEntry);
    103            }
    104
    105            /**
    106             * Adds a separator to the menu.
    107             */
    108            public void addMenuSeparator() {
    109                    if (menuColumn.getComponentCount() == 0) return;
    110                    menuSeparator = new Column();
    111                    menuSeparator.setInsets(new Insets(2, 0, 2, 0));
    112                    menuSeparator.setBackground(Style.mediumBackground);
    113                    Column line = new Column();
    114                    line.setBackground(Style.darkBackground);
    115                    line.setInsets(new Insets(0, 1, 0, 0));
    116                    menuSeparator.add(line);
    117            }
    118
    119            public void actionPerformed(ActionEvent e) {
    120                    setExpanded(false);
    121                    actionListener.actionPerformed(new ActionEvent(this, e.getActionCommand()));
    122            }
    123
    124    }