Exemplo n.º 1
0
  /**
   * createMenu
   *
   * @param label label of the menu
   * @param editor SciNotes
   * @param key KeyStroke
   * @return createMenu
   */
  public static Menu createMenu(String label, SciNotes editor, KeyStroke key) {
    StringTokenizer tokens = new StringTokenizer(label, ";\uff1b");
    String labelLineNumbering = tokens.nextToken();
    String labelOff = tokens.nextToken();
    String labelNormal = tokens.nextToken();
    String labelWhereami = tokens.nextToken();

    final LineNumbersAction ln = new LineNumbersAction(labelLineNumbering, editor);
    String[] labels = new String[] {labelOff, labelNormal, labelWhereami};

    final Menu menu = ScilabMenu.createMenu();
    menu.setText(labelLineNumbering);

    ln.arr[getState()].setSelected(true);

    for (int i = 0; i < 3; i++) {
      ((JMenu) menu.getAsSimpleMenu()).add(ln.arr[i]);
      ln.arr[i].setText(labels[i]);
    }

    ((JMenu) menu.getAsSimpleMenu())
        .addPropertyChangeListener(
            new PropertyChangeListener() {
              public void propertyChange(PropertyChangeEvent e) {
                ln.arr[getState()].setSelected(true);
              }
            });

    return menu;
  }
Exemplo n.º 2
0
 /**
  * Add a MenuItem to this MenuItem
  *
  * @param childMenuItem the MenuItem we want to add
  */
 public void add(SwingScilabMenuItem childMenuItem) {
   System.out.println("SwingScilabMenuItem.add(SwingScilabMenuItem childMenuItem)");
   if (meAsAMenu == null) {
     meAsAMenu = ScilabMenu.createMenu();
     meAsAMenu.setText(getText());
     ((SwingScilabMenu) meAsAMenu.getAsSimpleMenu()).add(childMenuItem);
     if (meAsACheckBoxMenuItem == null) {
       Container parent = getParent();
       int index = parent.getComponentZOrder(this);
       parent.remove(this.getComponent());
       parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
     } else {
       Container parent =
           ((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem())
               .getParent();
       int index =
           parent.getComponentZOrder(
               ((SwingScilabCheckBoxMenuItem)
                   meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()));
       parent.remove(
           ((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem())
               .getComponent());
       parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
     }
   } else {
     ((SwingScilabMenu) meAsAMenu.getAsSimpleMenu()).add(childMenuItem);
   }
 }
Exemplo n.º 3
0
 /** Destroy the MenuItem */
 public void destroy() {
   if (meAsAMenu != null) {
     ScilabSwingUtilities.removeFromParent((SwingScilabMenu) meAsAMenu.getAsSimpleMenu());
   } else if (meAsACheckBoxMenuItem != null) {
     ScilabSwingUtilities.removeFromParent(
         (SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem());
   } else {
     ScilabSwingUtilities.removeFromParent(this);
   }
 }
Exemplo n.º 4
0
 /**
  * Append a CheckBoxMenuItem to a Scilab Menu
  *
  * @param newCheckBoxMenuItem the CheckBoxMenuItem to add to the Menu
  * @see org.scilab.modules.gui.menu.Menu#add(org.scilab.modules.gui.CheckBoxMenuItem)
  */
 public void add(CheckBoxMenuItem newCheckBoxMenuItem) {
   if (meAsAMenu == null) {
     meAsAMenu = ScilabMenu.createMenu();
     meAsAMenu.setText(getText());
     meAsAMenu.add(newCheckBoxMenuItem);
     Container parent = getParent();
     int index = parent.getComponentZOrder(this);
     parent.remove(this.getComponent());
     parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
   } else {
     meAsAMenu.add(newCheckBoxMenuItem);
   }
 }