Package java.awt

Examples of java.awt.MenuItem$State


        //f.add(front);

        MenuBar mb = new MenuBar();
        Menu window = new Menu("Window");
        mb.add(window);
        MenuItem show_mi = new MenuItem("show");
        show_mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                f2.setVisible(true);
            }
        });
        window.add(show_mi);
        MenuItem hide_mi = new MenuItem("hide");
        hide_mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                f2.setVisible(false);
            }
        });
        window.add(hide_mi);
        MenuItem back_mi = new MenuItem("back");
        back_mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                f2.toBack();
            }
        });
        window.add(back_mi);
        MenuItem front_mi = new MenuItem("front");
        front_mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                f2.toFront();
            }
        });
        window.add(front_mi);
        window.addSeparator();
        MenuItem close_mi = new MenuItem("close");
        close_mi.addActionListener(close);
        window.add(close_mi);

        //popup menu
        final PopupMenu p_window = new PopupMenu("Window");
        MenuItem p_show_mi = new MenuItem("show");
        p_show_mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                f2.setVisible(true);
            }
        });
        p_window.add(p_show_mi);
        MenuItem p_hide_mi = new MenuItem("hide");
        p_hide_mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                f2.setVisible(false);
            }
        });
        p_window.add(p_hide_mi);
        MenuItem p_back_mi = new MenuItem("back");
        p_back_mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                f2.toBack();
            }
        });
        p_window.add(p_back_mi);
        MenuItem p_front_mi = new MenuItem("front");
        p_front_mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                f2.toFront();
            }
        });
        p_window.add(p_front_mi);
        p_window.addSeparator();
        MenuItem p_close_mi = new MenuItem("close");
        p_close_mi.addActionListener(close);
        p_window.add(p_close_mi);

        f.add(p_window);
        f.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent event) {
View Full Code Here


        addItem.addActionListener(new ActionListener() {
            int cnt = 1;

            public void actionPerformed(ActionEvent event) {
                for (Menu m : menuList) {
                    m.add(new MenuItem("Item " + cnt));
                }
                popup.add(new MenuItem("Item " + cnt));
                cnt++;
            }
        });
        f.add(addItem, BorderLayout.WEST);
        Button addSeparator = new Button("Add separator");
View Full Code Here

   MenuBar d5 = new MenuBar();
   harness.check(d5.getName(), "menubar3");
   harness.check(d4.getName(), "menubar4");
   harness.check(d3.getName(), "menubar5");
  
   MenuItem e0 = new MenuItem();
   MenuItem e1 = new MenuItem();
   MenuItem e2 = new MenuItem();
   harness.check(e0.getName(), "menuitem0");
   harness.check(e1.getName(), "menuitem1");
   harness.check(e2.getName(), "menuitem2");
   MenuItem e3 = new MenuItem();
   MenuItem e4 = new MenuItem();
   MenuItem e5 = new MenuItem();
   harness.check(e5.getName(), "menuitem3");
   harness.check(e4.getName(), "menuitem4");
   harness.check(e3.getName(), "menuitem5");
  
   Menu f0 = new Menu();
   Menu f1 = new Menu();
View Full Code Here

 
  public void test1(TestHarness harness)
  {
    harness.checkPoint("(MenuItem, int)");
    Menu menu = new Menu("Menu 1");
    MenuItem itemA = new MenuItem("Menu Item A");
    menu.insert(itemA, 0);
    harness.check(menu.getItem(0), itemA);
    MenuItem itemB = new MenuItem("Menu Item B");
    menu.insert(itemB, 1);
    harness.check(menu.getItem(1), itemB);
    MenuItem itemC = new MenuItem("Menu Item C");
    menu.insert(itemC, 0);
    harness.check(menu.getItem(0), itemC);
    harness.check(menu.getItem(1), itemA);
    harness.check(menu.getItem(2), itemB);
   
    // try negative index
    boolean pass = false;
    try
    {
      MenuItem itemD = new MenuItem("Menu Item D");
      menu.insert(itemD, -1);
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try index too large - item gets inserted at end of menu
    MenuItem itemD = new MenuItem("Menu Item D");
    menu.insert(itemD, 4);
    harness.check(menu.getItem(0), itemC);
    harness.check(menu.getItem(1), itemA);
    harness.check(menu.getItem(2), itemB);
    harness.check(menu.getItem(3), itemD);
View Full Code Here

    Menu m = new Menu("Menu 1");
    mb.add(m);
    f.setMenuBar(mb);
    f.add(new Button("Button"));
    f.pack();
    MenuItem itemA = new MenuItem("Item A");
    m.insert(itemA, 0);
    MenuItem itemB = new MenuItem("Item B");
    m.insert(itemB, 0);
    MenuItem itemC = new MenuItem("Item C");
    m.insert(itemC, 1);
    MenuItem itemD = new MenuItem("Item D");
    m.insert(itemD, 1);
    harness.check(m.getItem(0), itemB);
    harness.check(m.getItem(1), itemD);
    harness.check(m.getItem(2), itemC);
    harness.check(m.getItem(3), itemA);
View Full Code Here

    //MenuItem addToUserTabItem = new MenuItem("Add to user tab");
    for (int i = 0; i < TEMPLATE_PATHS.size(); i++) {
      String mE = TEMPLATE_DESCRIPTIONS.get(i);
      final String path = TEMPLATE_PATHS.get(i);
     
      MenuItem m = new MenuItem(mE);
      m.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ee) {
          try {
            InputStream inR = this.getClass().getClassLoader()
            .getResourceAsStream(path);
            m_mainKFPerspective.addTab("Untitled" + m_untitledCount++);
View Full Code Here

    //    beanContextMenu.insert(new JLabel("Edit",
    //              SwingConstants.CENTER),
    //         menuItemCount);
    boolean executing = m_mainKFPerspective.getExecuting();
   
    MenuItem edit = new MenuItem("Edit:");
    edit.setEnabled(false);
    beanContextMenu.insert(edit, menuItemCount);
    menuItemCount++;

    if (m_mainKFPerspective.getSelectedBeans().size() > 0) {
      MenuItem copyItem = new MenuItem("Copy");
      copyItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          copyToClipboard();
          m_mainKFPerspective.setSelectedBeans(new Vector());
        }
      });
      beanContextMenu.add(copyItem);
      copyItem.setEnabled(!executing);
      menuItemCount++;
    }


    if (bc instanceof MetaBean) {
      //JMenuItem ungroupItem = new JMenuItem("Ungroup");
      MenuItem ungroupItem = new MenuItem("Ungroup");
      ungroupItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          // ungroup
          bi.removeBean(m_beanLayout, m_mainKFPerspective.getCurrentTabIndex());

          Vector group = ((MetaBean) bc).getBeansInSubFlow();
          Vector associatedConnections = ((MetaBean) bc).getAssociatedConnections();
          ((MetaBean) bc).restoreBeans(xx, yy);

          for (int i = 0; i < group.size(); i++) {
            BeanInstance tbi = (BeanInstance) group.elementAt(i);
            addComponent(tbi, false);
            tbi.addBean(m_beanLayout, m_mainKFPerspective.getCurrentTabIndex());
          }

          for (int i = 0; i < associatedConnections.size(); i++) {
            BeanConnection tbc = (BeanConnection) associatedConnections.elementAt(i);
            tbc.setHidden(false);
          }

          m_beanLayout.repaint();
          m_mainKFPerspective.setEditedStatus(true);
          notifyIsDirty();           
        }
      });
      ungroupItem.setEnabled(!executing);
     
      beanContextMenu.add(ungroupItem);
      menuItemCount++;

      // Add to user tab
      //JMenuItem addToUserTabItem = new JMenuItem("Add to user tab");
      MenuItem addToUserTabItem = new MenuItem("Add to user tab");
      addToUserTabItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          //addToUserToolBar((MetaBean) bi.getBean(), true);
          //addToUserTreeNode((MetaBean) bi.getBean(), true);
          addToUserTreeNode(bi, true);
          notifyIsDirty();
        }
      });
      addToUserTabItem.setEnabled(!executing);
      beanContextMenu.add(addToUserTabItem);
      menuItemCount++;
    }

    //JMenuItem deleteItem = new JMenuItem("Delete");
    MenuItem deleteItem = new MenuItem("Delete");
    deleteItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        BeanConnection.removeConnections(bi, m_mainKFPerspective.getCurrentTabIndex());
        bi.removeBean(m_beanLayout, m_mainKFPerspective.getCurrentTabIndex());
        if (bc instanceof BeanCommon) {           
          String key = ((BeanCommon)bc).getCustomName()
          + "$" + bc.hashCode();
          m_logPanel.statusMessage(key + "|remove");
        }

        // delete any that have been actively selected
        if (m_mainKFPerspective.getSelectedBeans().size() > 0) {
          deleteSelectedBeans();
        }

        revalidate();
        m_mainKFPerspective.setEditedStatus(true);
        notifyIsDirty();
        m_selectAllB.setEnabled(BeanInstance.
            getBeanInstances(m_mainKFPerspective.getCurrentTabIndex()).size() > 0);
      }
    });
   
    deleteItem.setEnabled(!executing);
    if (bc instanceof BeanCommon) {
      if (((BeanCommon)bc).isBusy()) {
        deleteItem.setEnabled(false);
      }
    }

    beanContextMenu.add(deleteItem);
    menuItemCount++;

    if (bc instanceof BeanCommon) {
      MenuItem nameItem = new MenuItem("Set name");
      nameItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          String oldName = ((BeanCommon)bc).getCustomName();
          String name = JOptionPane.showInputDialog(KnowledgeFlowApp.this,
              "Enter a name for this component",
              oldName);
          if (name != null) {
            ((BeanCommon)bc).setCustomName(name);
            m_mainKFPerspective.setEditedStatus(true);
          }
        }
      });
      if (bc instanceof BeanCommon) {
        if (((BeanCommon)bc).isBusy()) {
          nameItem.setEnabled(false);
        }
      }
      nameItem.setEnabled(!executing);
      beanContextMenu.add(nameItem);
      menuItemCount++;
    }

    try {
      //BeanInfo [] compInfo = null;
      //JComponent [] associatedBeans = null;
      Vector compInfo = new Vector(1);
      Vector associatedBeans = null;
      Vector outputBeans = null;
      Vector compInfoOutputs = null;

      if (bc instanceof MetaBean) {
        compInfo = ((MetaBean) bc).getBeanInfoSubFlow();
        associatedBeans = ((MetaBean) bc).getBeansInSubFlow();

        outputBeans = ((MetaBean) bc).getBeansInOutputs();
        compInfoOutputs = ((MetaBean) bc).getBeanInfoOutputs();
      } else {
        compInfo.add(Introspector.getBeanInfo(bc.getClass()));
        compInfoOutputs = compInfo;
      }

      final Vector tempAssociatedBeans = associatedBeans;

      if (compInfo == null) {
        System.err.println("[KnowledgeFlow] Error in doPopup()");
      } else {
        //  System.err.println("Got bean info");
        for (int zz = 0; zz < compInfo.size(); zz++) {
          final int tt = zz;
          final Class custClass = ((BeanInfo) compInfo.elementAt(zz)).getBeanDescriptor()
          .getCustomizerClass();

          if (custClass != null) {
            //    System.err.println("Got customizer class");
            //    popupCustomizer(custClass, bc);
            //JMenuItem custItem = null;
            MenuItem custItem = null;
            boolean customizationEnabled = !executing;

            if (!(bc instanceof MetaBean)) {
              //custItem = new JMenuItem("Configure...");
              custItem = new MenuItem("Configure...");
              if (bc instanceof BeanCommon) {
                customizationEnabled = (!executing &&
                  !((BeanCommon)bc).isBusy());
              }
            } else {
              String custName = custClass.getName();
              BeanInstance tbi = (BeanInstance) associatedBeans.elementAt(zz);
              if (tbi.getBean() instanceof BeanCommon) {
                custName = ((BeanCommon)tbi.getBean()).getCustomName();
              } else {
                if (tbi.getBean() instanceof WekaWrapper) {
                  custName = ((WekaWrapper) tbi.getBean()).getWrappedAlgorithm()
                  .getClass().getName();
                } else {
                  custName = custName.substring(0, custName.indexOf("Customizer"));
                }

                custName = custName.substring(custName.lastIndexOf('.') + 1,             
                    custName.length());
              }
              //custItem = new JMenuItem("Configure: "+ custName);
              custItem = new MenuItem("Configure: " + custName);
              if (tbi.getBean() instanceof BeanCommon) {
                customizationEnabled = (!executing &&
                  !((BeanCommon)tbi.getBean()).isBusy());
              }
            }

            custItem.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                if (bc instanceof MetaBean) {
                  popupCustomizer(custClass,
                      (JComponent) ((BeanInstance) tempAssociatedBeans.
                          elementAt(tt)).getBean());
                } else {
                  popupCustomizer(custClass, bc);
                }

                notifyIsDirty();
              }
            });
            custItem.setEnabled(customizationEnabled);
            beanContextMenu.add(custItem);
            menuItemCount++;
          } else {
            System.err.println("[KnowledgeFlow] No customizer class");
          }
        }

        Vector esdV = new Vector();

        //for (int i = 0; i < compInfoOutputs.size(); i++) {
        for (int i = 0; i < compInfo.size(); i++) {
          EventSetDescriptor[] temp =
            //  ((BeanInfo) compInfoOutputs.elementAt(i)).getEventSetDescriptors();
            ((BeanInfo) compInfo.elementAt(i)).getEventSetDescriptors();

          if ((temp != null) && (temp.length > 0)) {
            esdV.add(temp);
          }
        }

        //        EventSetDescriptor [] esds = compInfo.getEventSetDescriptors();
        //        if (esds != null && esds.length > 0) {
        if (esdV.size() > 0) {
          //          beanContextMenu.insert(new JLabel("Connections",
          //                                            SwingConstants.CENTER),
          //                                 menuItemCount);
          MenuItem connections = new MenuItem("Connections:");
          connections.setEnabled(false);
          beanContextMenu.insert(connections, menuItemCount);
          menuItemCount++;
        }

        //final Vector finalOutputs = outputBeans;
        final Vector finalOutputs = associatedBeans;

        for (int j = 0; j < esdV.size(); j++) {
          final int fj = j;
          String sourceBeanName = "";

          if (bc instanceof MetaBean) {
            //Object sourceBean = ((BeanInstance) outputBeans.elementAt(j)).getBean();
            Object sourceBean = ((BeanInstance) associatedBeans.elementAt(j)).getBean();
            if (sourceBean instanceof BeanCommon) {
              sourceBeanName = ((BeanCommon)sourceBean).getCustomName();
            } else {
              if (sourceBean instanceof WekaWrapper) {
                sourceBeanName = ((WekaWrapper) sourceBean).getWrappedAlgorithm()
                .getClass().getName();
              } else {
                sourceBeanName = sourceBean.getClass().getName();
              }

              sourceBeanName =
                sourceBeanName.substring(sourceBeanName.lastIndexOf('.') + 1,
                    sourceBeanName.length());
            }
            sourceBeanName += ": ";
          }

          EventSetDescriptor[] esds = (EventSetDescriptor[]) esdV.elementAt(j);

          for (int i = 0; i < esds.length; i++) {
            //    System.err.println(esds[i].getName());
            // add each event name to the menu
            //            JMenuItem evntItem = new JMenuItem(sourceBeanName
            //                                               +esds[i].getName());
            MenuItem evntItem = new MenuItem(sourceBeanName +
                esds[i].getName());
            final EventSetDescriptor esd = esds[i];

            // Check EventConstraints (if any) here
            boolean ok = true;
            evntItem.setEnabled(!executing);

            if (bc instanceof EventConstraints) {
              ok = ((EventConstraints) bc).eventGeneratable(esd.getName());
            }

            if (ok) {
              evntItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  connectComponents(esd,
                      (bc instanceof MetaBean)
                      ? ((BeanInstance) finalOutputs.elementAt(fj)) : bi, xx, yy);
                  notifyIsDirty();
                }
              });
            } else {
              evntItem.setEnabled(false);
            }

            beanContextMenu.add(evntItem);
            menuItemCount++;
          }
        }
      }
    } catch (IntrospectionException ie) {
      ie.printStackTrace();
    }

    //    System.err.println("Just before look for other options");
    // now look for other options for this bean
    if (bc instanceof UserRequestAcceptor || bc instanceof Startable) {
      Enumeration req = null;

      if (bc instanceof UserRequestAcceptor) {
        req = ((UserRequestAcceptor) bc).enumerateRequests();
      }

      if (/*(bc instanceof Startable) ||*/ (req !=null && req.hasMoreElements())) {
        //  beanContextMenu.insert(new JLabel("Actions",
        //            SwingConstants.CENTER),
        //             menuItemCount);
        MenuItem actions = new MenuItem("Actions:");
        actions.setEnabled(false);
        beanContextMenu.insert(actions, menuItemCount);
        menuItemCount++;
      }

      /*if (bc instanceof Startable) {
        String tempS = ((Startable)bc).getStartMessage();
        insertUserOrStartableMenuItem(bc, true, tempS, beanContextMenu);
      }*/

      while (req != null && req.hasMoreElements()) {
        String tempS = (String) req.nextElement();
        insertUserOrStartableMenuItem(bc, false, tempS, beanContextMenu);
        menuItemCount++;
      }
    }

    // Send to perspective menu item?
    if (bc instanceof weka.gui.beans.Loader && m_perspectives.size() > 1 &&
        m_perspectiveDataLoadThread == null) {
      final weka.core.converters.Loader theLoader =
        ((weka.gui.beans.Loader)bc).getLoader();

      boolean ok = true;
      if (theLoader instanceof FileSourcedConverter) {
        String fileName = ((FileSourcedConverter)theLoader).
        retrieveFile().getPath();
        Environment env = m_mainKFPerspective.getEnvironmentSettings();
        try {
          fileName = env.substitute(fileName);
        } catch (Exception ex) {         
        }

        File tempF = new File(fileName);
        String fileNameFixedPathSep = fileName.replace(File.separatorChar, '/');
        if (!tempF.isFile() &&
            this.getClass().getClassLoader().getResource(fileNameFixedPathSep) == null) {
          ok = false;
        }
      }

      if (ok) {
        beanContextMenu.addSeparator();
        menuItemCount++;
        if (m_perspectives.size() > 2) {
          MenuItem sendToAllPerspectives = new MenuItem("Send to all perspectives");
          menuItemCount++;
          sendToAllPerspectives.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              loadDataAndSendToPerspective(theLoader, 0, true);
            }
          });
          beanContextMenu.add(sendToAllPerspectives);
        }
        Menu sendToPerspective = new Menu("Send to perspective...");
        beanContextMenu.add(sendToPerspective);
        menuItemCount++;
        for (int i = 1; i < m_perspectives.size(); i++) {
          final int pIndex = i;

          if (m_perspectives.get(i).acceptsInstances()) {
            String pName = m_perspectives.get(i).getPerspectiveTitle();
            MenuItem pI = new MenuItem(pName);
            pI.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                loadDataAndSendToPerspective(theLoader, pIndex, false);
              }
            });
            sendToPerspective.add(pI);
View Full Code Here

   
   
    PopupMenu trayPopup = new PopupMenu();

    // About
    MenuItem aboutItem = new MenuItem("About");
    aboutItem.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        showAbout();
      }
     
    });
    trayPopup.add(aboutItem);
   
    trayPopup.addSeparator();
   
    // Shutdown
    MenuItem shutdownItem = new MenuItem("Shutdown");
    shutdownItem.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        doShutdownCluster();
      }
View Full Code Here

        for (int i = 0; i < m.length; i++) {
            if (m[i].equals("-")) {
                f.addSeparator();
            } else {
                MenuItem item = new MenuItem(m[i]);

                item.addActionListener(this);
                f.add(item);
            }
        }
    }
View Full Code Here

            return;
        }

        String   s = ev.getActionCommand();
        MenuItem i = new MenuItem();

        if (s == null) {
            if (ev.getSource() instanceof MenuItem) {
                i = (MenuItem) ev.getSource();
                s = i.getLabel();
            }
        }

        if (s.equals("Start Transfer") || s.equals("ReStart Transfer")) {
            bStart.setLabel("ReStart Transfer");
View Full Code Here

TOP

Related Classes of java.awt.MenuItem$State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.