private void addMenuToTray() { HashMap categories = new HashMap(); // create menu list Iterator plugins = PluginManager.getInstance().getAvailablePlugins(); plugins = PluginComparator.sortPlugins(plugins); while (plugins.hasNext()) { Plugin p = (Plugin) plugins.next(); JMenu category = (JMenu) categories.get(p.getCategory()); if (category == null) { category = new JMenu(p.getCategory()); categories.put(p.getCategory(), category); // copy menu to real one if (!p.getCategory().equals("Invisible")) this.trayIcon.add(category); } ImageIcon icon = new ImageIcon(); try { icon = new ImageIcon(new URL(p.getDirectory() + p.getIcon())); icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH)); } catch (Exception e) { // error at icon loading } JMenuItem menu = new JMenuItem(p.getTitle(), icon); menu.setName(p.getName()); menu.setToolTipText(p.getToolTip()); menu.addActionListener(this); category.add(menu); } this.trayIcon.addSeparator(); // windows this.trayIcon.add(new WindowMenu(this)); // open main interface JMenuItem menu = new JMenuItem(tr("open")); menu.setName("org.lucane.applications.maininterface"); menu.addActionListener(this); this.trayIcon.add(menu); // exit menu = new JMenuItem(tr("exit")); menu.setName("exit"); menu.addActionListener(this); this.trayIcon.add(menu); }
public View(Model model) { this.model = model; model.makeMeObserver(this); frame = new JFrame(); statusbar = new JLabel(" 0"); board = new Board(); frame.add(board); JMenuBar menubar = new JMenuBar(); JMenu file = new JMenu("Settings"); file.setMnemonic(KeyEvent.VK_F); JMenuItem eMenuItem = new JMenuItem("New game"); eMenuItem.setToolTipText("Start a new game"); eMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = -1; setChanged(); notifyObservers(); menuEvent = 0; } }); file.add(eMenuItem); eMenuItem = new JMenuItem("Pause"); eMenuItem.setMnemonic(KeyEvent.VK_P); eMenuItem.setToolTipText("Set pause"); eMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 1; setChanged(); notifyObservers(); menuEvent = 0; } }); file.add(eMenuItem); JMenu imp = new JMenu("Set level"); imp.setMnemonic(KeyEvent.VK_M); JMenuItem lvl1 = new JMenuItem("level 1"); lvl1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 2; setChanged(); notifyObservers(); menuEvent = 0; } }); JMenuItem lvl2 = new JMenuItem("level 2"); lvl2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 3; setChanged(); notifyObservers(); menuEvent = 0; } }); JMenuItem lvl3 = new JMenuItem("level 3"); lvl3.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 4; setChanged(); notifyObservers(); menuEvent = 0; } }); JMenuItem lvl4 = new JMenuItem("level 4"); lvl4.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 5; setChanged(); notifyObservers(); menuEvent = 0; } }); JMenuItem lvl5 = new JMenuItem("level 5"); lvl5.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 6; setChanged(); notifyObservers(); menuEvent = 0; } }); imp.add(lvl1); imp.add(lvl2); imp.add(lvl3); imp.add(lvl4); imp.add(lvl5); file.add(imp); eMenuItem = new JMenuItem("Table of recorgs"); eMenuItem.setToolTipText("Show table of records"); eMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { recordDialog ad; try { ad = new recordDialog(); ad.setVisible(true); } catch (IOException e) { e.printStackTrace(); } } }); file.add(eMenuItem); eMenuItem = new JMenuItem("Exit"); eMenuItem.setMnemonic(KeyEvent.VK_C); eMenuItem.setToolTipText("Exit application"); eMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); file.add(eMenuItem); menubar.add(file); frame.setJMenuBar(menubar); statusbar.setPreferredSize(new Dimension(-1, 22)); statusbar.setBorder(LineBorder.createGrayLineBorder()); frame.add(statusbar, BorderLayout.SOUTH); frame.setSize(200, 400); frame.setTitle("Tetris"); frame.setLocationRelativeTo(null); }