public void propertyChange(final PropertyChangeEvent e) {
   if (myAlarm.getActiveRequestCount() == 0) {
     myInitialFocusedWindow = (Window) e.getOldValue();
     final MenuElement[] selectedPath = MenuSelectionManager.defaultManager().getSelectedPath();
     if (selectedPath.length == 0) { // there is no visible popup
       return;
     }
     Component firstComponent = null;
     for (final MenuElement menuElement : selectedPath) {
       final Component component = menuElement.getComponent();
       if (component instanceof JMenuBar) {
         firstComponent = component;
         break;
       } else if (component instanceof JPopupMenu) {
         firstComponent = ((JPopupMenu) component).getInvoker();
         break;
       }
     }
     if (firstComponent == null) {
       return;
     }
     final Window window = SwingUtilities.getWindowAncestor(firstComponent);
     if (window != myInitialFocusedWindow) { // focused window doesn't have popup
       return;
     }
   }
   myLastFocusedWindow = (Window) e.getNewValue();
   myAlarm.cancelAllRequests();
   myAlarm.addRequest(myClearSelectedPathRunnable, 150);
 }
    JMenuItem getItem() {
      JMenuItem i;

      if (null == cmd) {
        i = new JMenu(name);
        for (MenuElement e : submenu) {
          i.add(e.getItem());
        }
      } else {
        i = new JMenuItem(cmd.name());
        i.setActionCommand(cmd.name());
        i.addActionListener(menuListener);
      }

      return i;
    }
Exemple #3
0
 private void loadAction(DefaultMutableTreeNode node, MenuElement menu) {
   Object userObject = null;
   MenuElement menuElement = menu;
   if (menu.getSubElements().length > 0 && menu.getSubElements()[0] instanceof JPopupMenu) {
     menuElement = menu.getSubElements()[0];
   }
   for (MenuElement item : menuElement.getSubElements()) {
     if (item instanceof JMenuItem) {
       JMenuItem menuItem = ((JMenuItem) item);
       if (menuItem.getAction() != null) {
         Action action = menuItem.getAction();
         userObject = action;
         Object tb = action.getValue("toolbar");
         if (tb == null) {
           System.out.println(tr("Toolbar action without name: {0}", action.getClass().getName()));
           continue;
         } else if (!(tb instanceof String)) {
           if (!(tb instanceof Boolean) || (Boolean) tb) {
             System.out.println(tr("Strange toolbar value: {0}", action.getClass().getName()));
           }
           continue;
         } else {
           String toolbar = (String) tb;
           Action r = actions.get(toolbar);
           if (r != null && r != action && !toolbar.startsWith("imagery_")) {
             System.out.println(
                 tr(
                     "Toolbar action {0} overwritten: {1} gets {2}",
                     toolbar, r.getClass().getName(), action.getClass().getName()));
           }
           actions.put(toolbar, action);
         }
       } else {
         userObject = menuItem.getText();
       }
     }
     DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObject);
     node.add(newNode);
     loadAction(newNode, item);
   }
 }
Exemple #4
0
 private void addPluginExtensions(Set<? extends IdentifiableMenuEntry> points, RaplaMenu menu) {
   for (IdentifiableMenuEntry menuItem : points) {
     MenuElement menuElement = menuItem.getMenuElement();
     menu.add(menuElement.getComponent());
   }
 }
  public LabFrame() throws HeadlessException {
    super(title);
    JPanel pnl, pnl1;

    data = new LabData();

    alRootEntities.addAll(data.findRootEntities());

    JMenuBar mb = new JMenuBar();

    for (MenuElement e : menus) {
      mb.add(e.getItem());
    }
    setJMenuBar(mb);

    splMain = new JSplitPane();
    getContentPane().add(splMain);

    desktop = new JDesktopPane();
    desktop.setPreferredSize(new Dimension(400, 200));

    splMain.setRightComponent(desktop);

    lmEntities = new EntityListModel();

    lstEntities = new JList(lmEntities);
    lstEntities.getSelectionModel().addListSelectionListener(lmEntities);
    lstEntities.addMouseListener(dblClickListener);

    JScrollPane scpList = new JScrollPane(lstEntities);
    pnl = new JPanel(new BorderLayout(4, 4));

    pnl.add(scpList, BorderLayout.CENTER);

    pnl1 = new JPanel(null);
    pnl1.setLayout(new BoxLayout(pnl1, BoxLayout.X_AXIS));
    pnl1.add(Box.createHorizontalGlue());
    pnl1.add(new JButton(actNewEntity));
    pnl1.add(Box.createHorizontalGlue());
    pnl1.add(new JButton(actDelEntity));
    pnl1.add(Box.createHorizontalGlue());
    pnl.add(pnl1, BorderLayout.SOUTH);

    splMain.setLeftComponent(pnl);

    il =
        new InternalFrameAdapter() {

          @Override
          public void internalFrameClosed(InternalFrameEvent e) {
            Object sel = ((EntityFrame) e.getInternalFrame()).content;
            mapEntityFrames.remove(sel);
          }

          @Override
          public void internalFrameActivated(InternalFrameEvent e) {
            setTitle(title + " - " + e.getInternalFrame().getTitle());
            Object sel = ((EntityFrame) e.getInternalFrame()).content;
            lstEntities.setSelectedValue(sel, true);
          }
        };
    pack();

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setVisible(true);

    updateState();
  }