LookManager(JButton arrowbutton, PopupPanel popuppanel) {
   arrow = arrowbutton;
   popup = popuppanel;
   popup.addPopupMenuListener(this);
   initButton(arrow);
   arrow.addMouseListener(this);
 }
  private void showPopup() {
    if (isEnabled()) {
      if (popup.isVisible()) {
        popup.setVisible(false);
      } else {
        Component[] components = popup.getComponents();
        if (components != null) {
          for (int i = 0; i < components.length; i++) {
            if (components[i] instanceof Item) ((Item) components[i]).removeActionListener(this);
            else if (components[i] instanceof MenuItem) {
              Component[] subcomponents = ((MenuItem) components[i]).getComponents();
              for (int j = 0; j < components.length; j++) {
                if (components[j] instanceof Item)
                  ((Item) components[j]).removeActionListener(this);
              }
            }
          }
        }
        popup.removeAll();
        if (values == null) return;
        for (int i = 0; i < values.length; i++) {
          JMenuItem item = null;
          if (values[i] instanceof ListDescriptor) {
            ListDescriptor descriptor = (ListDescriptor) values[i];
            Icon icon = descriptor.getIcon();
            item = new Item(values[i].toString(), icon, i);
            item.addActionListener(this);
          } else if (values[i] instanceof AddElement) {
            AddElement element = (AddElement) values[i];
            Icon icon = element.getIcon();

            Object[] choiceValues = element.getChoiceValues();
            if (choiceValues != null) {
              item = new MenuItem(element.toString(), icon, i);
              for (int j = 0; j < choiceValues.length; j++) {
                if (choiceValues[j] == null) {
                  ((JMenu) item).addSeparator();
                  continue;
                }
                Item subItem = new Item(choiceValues[j].toString(), j);
                ((JMenu) item).add(subItem);
                subItem.setParentIndex(i);
                subItem.addActionListener(this);
              }
            } else {
              item = new Item(element.toString(), icon, i);
              item.addActionListener(this);
            }
            item.setVisible(element.isVisible());
            item.setEnabled(element.isEnabled());
          } else {
            if (values[i] != null) {
              item = new Item(values[i].toString(), i);
              item.addActionListener(this);
            }
          }
          if (item != null) {
            popup.add(item);
          } else popup.addSeparator();
        }
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                AwtUtil.showPopupPanel(PopupMenuButton.this, popup);
              }
            });
      }
    }
  }
 public void updateUI() {
   super.updateUI();
   if (popup != null) popup.updateUI();
 }