001package ca.bc.webarts.applets.menu.gui;
002import java.awt.*;
003import java.awt.event.*;
004
005import ca.bc.webarts.applets.menu.*;
006
007public class MyPopupButton extends MyMenuButton implements ActionListener
008{
009
010  public PopupMenu popup;
011  public int n;
012  private int menuItems = 0;
013  private int menuHeight = 0;
014  private int menuItemHeight = 21;
015  private int sepHeight = 8;
016  public boolean popuped;
017  MyMenu applet;
018
019  public MyPopupButton(int i, MyMenu myMenu,
020                       MyMainMenuPanel mainmenupanel)
021  {
022  applet = myMenu;
023  n = i;
024  String[] strings = (mainmenupanel.tokenString
025         (applet.propt.getProperty("menu" + i, "WebARTS"), "|"));
026  this.setLabel(strings[0].trim());
027  menuItems = strings.length;
028  if (menuItems > 1)
029  {
030      this.addActionListener(this);
031      popup = new PopupMenu();
032      popuped = true;
033      for (int j = 1; j < menuItems; j++)
034      {
035        strings[j].trim();
036        String[] menuItemStr = mainmenupanel.tokenString(strings[j], "*");
037        if (menuItemStr.length > 1)
038        {
039          Menu menu = new Menu(menuItemStr[0].trim());
040          for (int k = 1; k < menuItemStr.length; k++)
041          {
042            if (menuItemStr[k].trim() == "-")
043            {
044                menu.addSeparator();
045                menuHeight += sepHeight;
046            }
047            else
048            {
049                MenuItem menuitem  = new MenuItem(menuItemStr[k].trim());
050                menuitem.addActionListener(mainmenupanel);
051                menu.add(menuitem);
052                menuHeight += menuItemHeight;
053            }
054          }
055          popup.add(menu);
056        }
057        else
058        {
059          if (strings[j].trim() == "-")
060          {
061            popup.addSeparator();
062            menuHeight += sepHeight;
063          }
064          else
065          {
066            MenuItem menuitem = new MenuItem(strings[j].trim());
067            menuitem.addActionListener(mainmenupanel);
068            popup.add(menuitem);
069            menuHeight += menuItemHeight;
070          }
071        }
072      }
073      this.add(popup);
074    }
075    else
076      this.addActionListener(mainmenupanel);
077  }
078
079  public void actionPerformed(ActionEvent actionevent)
080  {
081    applet.pop.play();
082    int buttonHeight = this.getSize().height;
083    popup.show(this, 0, buttonHeight+menuHeight);
084  }
085}