protected final MenuItem createMenuItem(String _key, String _header, ActionListener _al) {
   MenuItem mi = new MenuItem(res.getString("TabbedEditor." + _key));
   mi.setActionCommand(_key);
   mi.addActionListener(_al);
   popupMenu.add(mi);
   return mi;
 }
  /**
   * Method declaration
   *
   * @param s
   */
  private void addToRecent(String s) {

    for (int i = 0; i < iMaxRecent; i++) {
      if (s.equals(sRecent[i])) {
        return;
      }
    }

    if (sRecent[iRecent] != null) {
      mRecent.remove(iRecent);
    }

    sRecent[iRecent] = s;

    if (s.length() > 43) {
      s = s.substring(0, 40) + "...";
    }

    MenuItem item = new MenuItem(s);

    item.setActionCommand("#" + iRecent);
    item.addActionListener(this);
    mRecent.insert(item, iRecent);

    iRecent = (iRecent + 1) % iMaxRecent;
  }
Example #3
0
private void MenuPopup (MouseEvent ev, CGNode node)
    {
	if (!node.IsConcept())
	    return;

	String menuname = (String)menumap.get (node.GetType(true));
	if (menuname == null)
	    return;
	Hashtable templates = (Hashtable)menus.get (menuname);
	if (templates == null)
	    return;

	if( popup != null )
	  remove( popup );

	popup = new PopupMenu( menuname );
	
        Enumeration e = templates.keys();
        while (e.hasMoreElements()) {
            String key = (String)e.nextElement();
	    MenuItem mi = new MenuItem( key );
	    mi.setActionCommand( key );
	    mi.addActionListener( this );
	    popup.add( mi );
        }
        curnode = node;

	this.add( popup );

	popup.show( this, ev.getX(), ev.getY() );
    }
Example #4
0
  /** @throws AWTException */
  public SysTray() {

    if (SystemTray.isSupported()) {
      LOG.fine("O sistema possui suporte a ícone de bandeja.");

      SystemTray sys = SystemTray.getSystemTray();

      // cria o menu popup
      PopupMenu popup = new PopupMenu();

      MenuItem miExibe = new MenuItem("Exibir Painel");
      miExibe.setActionCommand("exibir");
      miExibe.addActionListener(this);
      popup.add(miExibe);

      popup.addSeparator();

      MenuItem miConf = new MenuItem("Configurar Serviços");
      miConf.setActionCommand("configurar");
      miConf.addActionListener(this);
      popup.add(miConf);

      MenuItem miConfLay = new MenuItem("Configurar Layout");
      miConfLay.setActionCommand("layout");
      miConfLay.addActionListener(this);
      popup.add(miConfLay);

      popup.addSeparator();

      MenuItem miSobre = new MenuItem("Sobre");
      miSobre.setActionCommand("sobre");
      miSobre.addActionListener(this);
      popup.add(miSobre);

      popup.addSeparator();

      MenuItem miSair = new MenuItem("Sair");
      miSair.setActionCommand("sair");
      miSair.addActionListener(this);
      popup.add(miSair);

      // constroi o system tray
      TrayIcon trayIcon = new TrayIcon(ImagesTable.SGA_ICON.getImage(), "Painel SGA", popup);

      // Ajusta ao tamanho do respectivo Sistema Operacional automaticamente
      trayIcon.setImageAutoSize(true);

      // adiciona imagem do system tray
      try {
        sys.add(trayIcon);
        LOG.fine("Ícone de bandeja exibido com sucesso.");
      } catch (AWTException e) {
        Mensagem.showMensagem(
            "Falha ao adicionar o Ícone na bandeja.\nDetalhe: " + e.getMessage(), "Erro", 0);
        System.exit(1);
      }
    } else {
      Mensagem.showMensagem("Seu sistema não suporta Ícone de bandeja.", "Erro", 0);
      System.exit(1);
    }
  }
  /**
   * Create the GUI and show it. For thread safety, this method should be invoked from the event
   * dispatch thread.
   */
  public static void createAndShowGUI() {
    java.io.File file = new java.io.File("marau.properties");
    final java.util.Properties properties = new java.util.Properties();
    try {
      file.createNewFile();
      properties.load(new java.io.FileInputStream(file));
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if (properties.getProperty("XMLFile") == null || properties.getProperty("XMLFile").isEmpty()) {
      properties.setProperty("XMLFile", "test.xml");
    }

    // Create and set up the window.
    JFrame frame = new JFrame("Marau");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // Add contents to the window.
    final GuiMainApp win = new GuiMainApp(properties);
    win.setOpaque(true); // content panes must be opaque
    frame.setContentPane(win);
    // GuiMainApp win = new GuiMainApp();
    // frame.add(win);
    final int defaultWidth = 800;
    final int defaultHeight = 400;
    frame.setSize(defaultWidth, defaultHeight);
    frame.setLocationRelativeTo(null);

    URL imgPath = win.getClass().getClassLoader().getResource("fr/marau/gui/velo2.jpg");
    Image img = Toolkit.getDefaultToolkit().getImage(imgPath);
    frame.setIconImage(img);

    // Display the window.
    frame.setVisible(true);

    MenuBar test = new MenuBar();
    Menu menu1 = new Menu("Fichier");
    MenuItem item1 = new MenuItem("Ouvrir");
    item1.setActionCommand("Open");
    menu1.add(item1);
    item1 = new MenuItem("Load");
    item1.setActionCommand("Load");
    menu1.add(item1);
    item1 = new MenuItem("Save");
    item1.setActionCommand("save");
    menu1.add(item1);
    item1 = new MenuItem("Save As");
    item1.setActionCommand("saveAs");
    menu1.add(item1);
    menu1.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            if (arg0.getActionCommand().equals("save")) {
              new CreateXMLFile(win.getLudo(), properties.getProperty("XMLFile"), properties);
            } else if (arg0.getActionCommand().equals("Open")) {
              final JFileChooser fc = new JFileChooser();
              int returnVal = fc.showOpenDialog(win);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                properties.setProperty("XMLFile", file.getPath());
              }
            } else if (arg0.getActionCommand().equals("saveAs")) {
              final JFileChooser fc = new JFileChooser();
              int returnVal = fc.showOpenDialog(win);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                new CreateXMLFile(win.getLudo(), file.getPath(), properties);
              }
            } else if (arg0.getActionCommand().equals("Load")) {
              win.Load();
            }
          }
        });

    test.add(menu1);
    frame.setMenuBar(test);
  }
Example #6
0
  /** Create the whole GUI, and set up event listeners */
  public AllComponents(String title) {
    super(title); // set frame title.

    // Arrange to detect window close events
    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    // Set a default font
    this.setFont(new Font("SansSerif", Font.PLAIN, 12));

    // Create the menubar.  Tell the frame about it.
    MenuBar menubar = new MenuBar();
    this.setMenuBar(menubar);

    // Create the file menu.  Add to menubar.
    Menu file = new Menu("File");
    menubar.add(file);

    // Create two items for the file menu, setting their label, shortcut,
    // action command and listener.  Add them to File menu.
    // Note that we use the frame itself as the action listener
    MenuItem open = new MenuItem("Open", new MenuShortcut(KeyEvent.VK_O));
    open.setActionCommand("open");
    open.addActionListener(this);
    file.add(open);
    MenuItem quit = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q));
    quit.setActionCommand("quit");
    quit.addActionListener(this);
    file.add(quit);

    // Create Help menu; add an item; add to menubar
    // Display the help menu in a special reserved place.
    Menu help = new Menu("Help");
    menubar.add(help);
    menubar.setHelpMenu(help);

    // Create and add an item to the Help menu
    MenuItem about = new MenuItem("About", new MenuShortcut(KeyEvent.VK_A));
    about.setActionCommand("about");
    about.addActionListener(this);
    help.add(about);

    // Now that we've done the menu, we can begin work on the contents of
    // the frame.  Assign a BorderLayout manager with margins for this frame.
    this.setLayout(new BorderLayout(10, 10));

    // Create two panels to contain two columns of components.  Use our custom
    // ColumnLayout layout manager for each.  Add them on the west and
    // center of the frame's border layout
    Panel column1 = new Panel();
    column1.setLayout(new ColumnLayout(5, 10, 2, ColumnLayout.LEFT));
    this.add(column1, "West");
    Panel column2 = new Panel();
    column2.setLayout(new ColumnLayout(5, 10, 2, ColumnLayout.LEFT));
    this.add(column2, "Center");

    // Create a panel to contain the buttons at the bottom of the window
    // Give it a FlowLayout layout manager, and add it along the south border
    Panel buttonbox = new Panel();
    buttonbox.setLayout(new FlowLayout(FlowLayout.CENTER, 100, 10));
    this.add(buttonbox, "South");

    // Create pushbuttons and add them to the buttonbox
    Button okay = new Button("Okay");
    Button cancel = new Button("Cancel");
    buttonbox.add(okay);
    buttonbox.add(cancel);

    // Handle events on the buttons
    ActionListener buttonlistener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            textarea.append("You clicked: " + ((Button) e.getSource()).getLabel() + "\n");
          }
        };
    okay.addActionListener(buttonlistener);
    cancel.addActionListener(buttonlistener);

    // Now start filling the left column.
    // Create a 1-line text field and add to left column, with a label
    TextField textfield = new TextField(15);
    column1.add(new Label("Name:"));
    column1.add(textfield);

    // Handle events on the TextField
    textfield.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            textarea.append("Your name is: " + ((TextField) e.getSource()).getText() + "\n");
          }
        });
    textfield.addTextListener(
        new TextListener() {
          public void textValueChanged(TextEvent e) {
            textarea.append("You have typed: " + ((TextField) e.getSource()).getText() + "\n");
          }
        });

    // Create a dropdown list or option menu of choices
    Choice choice = new Choice();
    choice.addItem("red");
    choice.addItem("green");
    choice.addItem("blue");
    column1.add(new Label("Favorite color:"));
    column1.add(choice);

    // Handle events on this choice
    choice.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            textarea.append("Your favorite color is: " + e.getItem() + "\n");
          }
        });

    // Create checkboxes, and group them in a CheckboxGroup to give them
    // "radio button" behavior.
    CheckboxGroup checkbox_group = new CheckboxGroup();
    Checkbox[] checkboxes = new Checkbox[3];
    checkboxes[0] = new Checkbox("vanilla", checkbox_group, false);
    checkboxes[1] = new Checkbox("chocolate", checkbox_group, true);
    checkboxes[2] = new Checkbox("strawberry", checkbox_group, false);
    column1.add(new Label("Favorite flavor:"));
    for (int i = 0; i < checkboxes.length; i++) column1.add(checkboxes[i]);

    // Handle events on the checkboxes
    ItemListener checkbox_listener =
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            textarea.append(
                "Your favorite flavor is: " + ((Checkbox) e.getItemSelectable()).getLabel() + "\n");
          }
        };
    for (int i = 0; i < checkboxes.length; i++) checkboxes[i].addItemListener(checkbox_listener);

    // Create a list of choices.
    List list = new List(4, true);
    list.addItem("Java");
    list.addItem("C");
    list.addItem("C++");
    list.addItem("Smalltalk");
    list.addItem("Lisp");
    list.addItem("Modula-3");
    list.addItem("Forth");
    column1.add(new Label("Favorite languages:"));
    column1.add(list);
    // Handle events on this list
    list.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            textarea.append("Your favorite languages are: ");
            String[] languages = ((List) e.getItemSelectable()).getSelectedItems();
            for (int i = 0; i < languages.length; i++) {
              if (i > 0) textarea.append(",");
              textarea.append(languages[i]);
            }
            textarea.append("\n");
          }
        });

    // Create a multi-line text area in column 2
    textarea = new TextArea(6, 40);
    textarea.setEditable(false);
    column2.add(new Label("Messages"));
    column2.add(textarea);

    // Create a scrollpane that displays portions of a larger component
    ScrollPane scrollpane = new ScrollPane();
    scrollpane.setSize(300, 150);
    column2.add(new Label("Scrolling Window"));
    column2.add(scrollpane);

    // Create a custom MultiLineLabel with a really big font and make it
    // a child of the ScrollPane container
    String message =
        "/*************************************************\n"
            + " * AllComponents.java                            *\n"
            + " * Written by David Flanagan                     *\n"
            + " * Copyright (c) 1997 by O'Reilly & Associates   *\n"
            + " *                                               *\n"
            + " *************************************************/\n";
    MultiLineLabel biglabel = new MultiLineLabel(message);
    biglabel.setFont(new Font("Monospaced", Font.BOLD + Font.ITALIC, 24));
    scrollpane.add(biglabel);
  }
 void install() {
   subMenus.clear();
   if (text != null) {
     Tokenizer tok = new Tokenizer();
     pgm = tok.tokenize(text);
   }
   if (macrosMenu != null) IJ.showStatus("");
   int[] code = pgm.getCode();
   Symbol[] symbolTable = pgm.getSymbolTable();
   int count = 0, token, nextToken, address;
   String name;
   Symbol symbol;
   shortcutsInUse = null;
   inUseCount = 0;
   nShortcuts = 0;
   toolCount = 0;
   macroStarts = new int[MAX_MACROS];
   macroNames = new String[MAX_MACROS];
   boolean isPluginsMacrosMenu = false;
   if (macrosMenu != null) {
     int itemCount = macrosMenu.getItemCount();
     isPluginsMacrosMenu = macrosMenu == Menus.getMacrosMenu();
     int baseCount = isPluginsMacrosMenu ? MACROS_MENU_COMMANDS : Editor.MACROS_MENU_ITEMS;
     if (itemCount > baseCount) {
       for (int i = itemCount - 1; i >= baseCount; i--) macrosMenu.remove(i);
     }
   }
   if (pgm.hasVars() && pgm.macroCount() > 0 && pgm.getGlobals() == null)
     new Interpreter().saveGlobals(pgm);
   ArrayList tools = new ArrayList();
   for (int i = 0; i < code.length; i++) {
     token = code[i] & TOK_MASK;
     if (token == MACRO) {
       nextToken = code[i + 1] & TOK_MASK;
       if (nextToken == STRING_CONSTANT) {
         if (count == MAX_MACROS) {
           if (isPluginsMacrosMenu)
             IJ.error("Macro Installer", "Macro sets are limited to " + MAX_MACROS + " macros.");
           break;
         }
         address = code[i + 1] >> TOK_SHIFT;
         symbol = symbolTable[address];
         name = symbol.str;
         macroStarts[count] = i + 2;
         macroNames[count] = name;
         if (name.indexOf('-') != -1
             && (name.indexOf("Tool") != -1 || name.indexOf("tool") != -1)) {
           tools.add(name);
           toolCount++;
         } else if (name.startsWith("AutoRun")) {
           if (autoRunCount == 0 && !openingStartupMacrosInEditor) {
             new MacroRunner(pgm, macroStarts[count], name, (String) null);
             if (name.equals("AutoRunAndHide")) autoRunAndHideCount++;
           }
           autoRunCount++;
           count--;
         } else if (name.equals("Popup Menu")) installPopupMenu(name, pgm);
         else if (!name.endsWith("Tool Selected")) {
           if (macrosMenu != null) {
             addShortcut(name);
             int pos = name.indexOf(">");
             boolean inSubMenu = name.startsWith("<") && (pos > 1);
             if (inSubMenu) {
               Menu parent = macrosMenu;
               Menu subMenu = null;
               String parentStr = name.substring(1, pos).trim();
               String childStr = name.substring(pos + 1).trim();
               MenuItem mnuItem = new MenuItem();
               mnuItem.setActionCommand(name);
               mnuItem.setLabel(childStr);
               for (int jj = 0; jj < subMenus.size(); jj++) {
                 String aName = subMenus.get(jj).getName();
                 if (aName.equals(parentStr)) subMenu = subMenus.get(jj);
               }
               if (subMenu == null) {
                 subMenu = new Menu(parentStr);
                 subMenu.setName(parentStr);
                 subMenu.addActionListener(this);
                 subMenus.add(subMenu);
                 parent.add(subMenu);
               }
               subMenu.add(mnuItem);
             } else macrosMenu.add(new MenuItem(name));
           }
         }
         // IJ.log(count+" "+name+" "+macroStarts[count]);
         count++;
       }
     } else if (token == EOF) break;
   }
   nMacros = count;
   if (toolCount > 0 && (isPluginsMacrosMenu || macrosMenu == null) && installTools) {
     Toolbar tb = Toolbar.getInstance();
     if (toolCount == 1) tb.addMacroTool((String) tools.get(0), this);
     else {
       for (int i = 0; i < tools.size(); i++) {
         String toolName = (String) tools.get(i);
         if (toolName.startsWith("Abort Macro or Plugin") && toolCount > 6)
           toolName = "Unused " + toolName;
         tb.addMacroTool(toolName, this, i);
       }
     }
     if (toolCount > 1 && Toolbar.getToolId() >= Toolbar.CUSTOM1) tb.setTool(Toolbar.RECTANGLE);
     tb.repaint();
   }
   if (macrosMenu != null) this.instance = this;
   if (shortcutsInUse != null && text != null)
     IJ.showMessage(
         "Install Macros",
         (inUseCount == 1 ? "This keyboard shortcut is" : "These keyboard shortcuts are")
             + " already in use:"
             + shortcutsInUse);
   if (nMacros == 0 && fileName != null) {
     if (text == null || text.length() == 0) return;
     int dotIndex = fileName.lastIndexOf('.');
     if (dotIndex > 0) anonymousName = fileName.substring(0, dotIndex);
     else anonymousName = fileName;
     if (macrosMenu != null) macrosMenu.add(new MenuItem(anonymousName));
     macroNames[0] = anonymousName;
     nMacros = 1;
   }
   String word = nMacros == 1 ? " macro" : " macros";
   if (isPluginsMacrosMenu) IJ.showStatus(nMacros + word + " installed");
 }