private void initFontMenu() { Menu fontMenu = new Menu("font"); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fontSet = ge.getAllFonts(); List<String> list = new ArrayList<>(); for (Font f : fontSet) { list.add(f.getName()); } int num = DigitalClockWindow.EXCLUDED_FONTS.length; for (int i = 0; i < num; i++) { list.remove(DigitalClockWindow.EXCLUDED_FONTS[i]); } for (final String fontName : list) { MenuItem mi = new MenuItem(fontName); mi.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DigitalClockProperty.PROPERTY.setFontName(fontName); digitalClockPropertyObserver.notifyPropertyChanged(DigitalClockProperty.PROPERTY); DigitalClockPopupMenu.this.setFont(POPUP_MENU_FONT); } }); fontMenu.add(mi); } add(fontMenu); }
public SplashDemo() throws NullPointerException, IllegalStateException, IOException { super("SplashScreen demo"); setSize(300, 200); setLayout(new BorderLayout()); Menu m1 = new Menu("File"); MenuItem mi1 = new MenuItem("Exit"); m1.add(mi1); mi1.addActionListener(this); this.addWindowListener(closeWindow); MenuBar mb = new MenuBar(); setMenuBar(mb); mb.add(m1); final SplashScreen splash = SplashScreen.getSplashScreen(); if (splash == null) { System.out.println("SplashScreen.getSplashScreen() returned null"); return; } Graphics2D g = splash.createGraphics(); if (g == null) { System.out.println("g is null"); return; } for (int i = 0; i < 100; i++) { renderSplashFrame(g, i); splash.update(); try { Thread.sleep(90); } catch (InterruptedException e) { } } splash.close(); setVisible(true); toFront(); }
private void initFontColorMenu() { Menu fontColorMenu = new Menu("font color"); for (final Entry<String, Color> colorEntry : colorSet.entrySet()) { MenuItem mi = new MenuItem(colorEntry.getKey()); mi.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (colorEntry .getValue() .equals(DigitalClockProperty.PROPERTY.getBackgroungColor())) { ErrorMessageDialog.showErrorMessage( colorEntry.getKey() + " is same color of background. Select different color for font."); return; } DigitalClockProperty.PROPERTY.setFontColor(colorEntry.getValue()); digitalClockPropertyObserver.notifyPropertyChanged(DigitalClockProperty.PROPERTY); DigitalClockPopupMenu.this.setFont(POPUP_MENU_FONT); } }); fontColorMenu.add(mi); } add(fontColorMenu); }
/** * 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; }
/** Handles CheckboxMenuItem state changes. */ public void itemStateChanged(ItemEvent e) { MenuItem item = (MenuItem) e.getSource(); MenuComponent parent = (MenuComponent) item.getParent(); String cmd = e.getItem().toString(); if ((Menu) parent == Menus.window) WindowManager.activateWindow(cmd, item); else doCommand(cmd); }
DigitalClockPopupMenu(DigitalClockPropertyObserver digitalClockPropertyObserver) { this.digitalClockPropertyObserver = digitalClockPropertyObserver; setFont(POPUP_MENU_FONT); colorSet.put("BLACK", Color.BLACK); colorSet.put("BLUE", Color.BLUE); colorSet.put("CYAN", Color.CYAN); colorSet.put("DARK GRAY", Color.DARK_GRAY); colorSet.put("GRAY", Color.GRAY); colorSet.put("GREEN", Color.GREEN); colorSet.put("LIGTHT GRAY", Color.LIGHT_GRAY); colorSet.put("MAGENTA", Color.MAGENTA); colorSet.put("ORANGE", Color.ORANGE); colorSet.put("PINK", Color.PINK); colorSet.put("RED", Color.RED); colorSet.put("WHITE", Color.WHITE); colorSet.put("YELLOW", Color.YELLOW); initFontMenu(); initFontSizeMenu(); initFontColorMenu(); initBackgroungColorMenu(); addSeparator(); MenuItem exitMenu = new MenuItem("exit"); exitMenu.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); add(exitMenu); }
protected PopupMenu getNetTunnelMenu(NetTunnel tunnel) { PopupMenu menu = new PopupMenu(); PopupMenuListener pml = new NetTunnelPopupListener(tunnel, controller); String[] items = { "Track roadusers arrived", "Track trip waiting time", "Track waiting (receive) queue", "Track send queue" }; MenuItem item; for (int i = 0; i < items.length; i++) { item = new MenuItem(items[i]); item.addActionListener(pml); menu.add(item); } menu.add(new MenuItem("-")); item = new MenuItem("Properties...", new MenuShortcut(KeyEvent.VK_ENTER)); item.addActionListener(pml); menu.add(item); return menu; }
/** Handle menu events. */ public void actionPerformed(ActionEvent e) { if ((e.getSource() instanceof MenuItem)) { MenuItem item = (MenuItem) e.getSource(); String cmd = e.getActionCommand(); commandName = cmd; ImagePlus imp = null; if (item.getParent() == Menus.getOpenRecentMenu()) { new RecentOpener(cmd); // open image in separate thread return; } else if (item.getParent() == Menus.getPopupMenu()) { Object parent = Menus.getPopupMenu().getParent(); if (parent instanceof ImageCanvas) imp = ((ImageCanvas) parent).getImage(); } int flags = e.getModifiers(); hotkey = false; actionPerformedTime = System.currentTimeMillis(); long ellapsedTime = actionPerformedTime - keyPressedTime; if (cmd != null && (ellapsedTime >= 200L || !cmd.equals(lastKeyCommand))) { if ((flags & Event.ALT_MASK) != 0) IJ.setKeyDown(KeyEvent.VK_ALT); if ((flags & Event.SHIFT_MASK) != 0) IJ.setKeyDown(KeyEvent.VK_SHIFT); new Executer(cmd, imp); } lastKeyCommand = null; if (IJ.debugMode) IJ.log("actionPerformed: time=" + ellapsedTime + ", " + e); } }
public void setFormatsMenu(FileFormat[] supportedFormats, jMESYS t) throws Exception { if (supportedFormats != null) { int lenFormats = supportedFormats.length; System.out.println("Leo Formatos..."); for (int i = 0; i < lenFormats; i++) { jMESYSMenuItem mItem = new jMESYSMenuItem(supportedFormats[i].getExtension(), supportedFormats[i]); System.out.println(supportedFormats[i].getFileName()); mItem.setFileName(supportedFormats[i].getFileName()); mItem.addActionListener(t); mOpen.add(mItem); } mOpen.addSeparator(); MenuItem allFormats = new MenuItem("All Formats"); allFormats.addActionListener(t); mOpen.add(allFormats); mOpen.addSeparator(); MenuItem mWOS = new MenuItem("Remote WOS"); mWOS.addActionListener(t); mOpen.add(mWOS); } else { System.out.println("+++No supported files+++"); } }
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; }
/* * Get the item with the given name either from the menuBar, or if * that is null, from the menu. */ protected static MenuItem getMenuItem( MenuBar menuBar, Menu menu, String name, boolean createIfNecessary) { if (menuBar == null && menu == null) return null; if (menuBar != null && name.equals("Help")) { menu = menuBar.getHelpMenu(); if (menu == null && createIfNecessary) { menu = new PopupMenu("Help"); menuBar.setHelpMenu(menu); } return menu; } int count = menuBar != null ? menuBar.getMenuCount() : menu.getItemCount(); for (int i = 0; i < count; i++) { MenuItem current = menuBar != null ? menuBar.getMenu(i) : menu.getItem(i); if (name.equals(current.getLabel())) return current; } if (createIfNecessary) { Menu newMenu = new PopupMenu(name); if (menuBar != null) menuBar.add(newMenu); else menu.add(newMenu); return newMenu; } else return null; }
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() ); }
private MainPanel(final JFrame frame) { super(); add(check); setPreferredSize(new Dimension(320, 240)); if (!SystemTray.isSupported()) { frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); return; } frame.addWindowListener( new WindowAdapter() { @Override public void windowIconified(WindowEvent e) { if (check.isSelected()) { e.getWindow().dispose(); } } }); // or // frame.addWindowStateListener(new WindowStateListener() { // @Override public void windowStateChanged(WindowEvent e) { // if (check.isSelected() && e.getNewState() == Frame.ICONIFIED) { // e.getWindow().dispose(); // } // } // }); final SystemTray tray = SystemTray.getSystemTray(); Dimension d = tray.getTrayIconSize(); BufferedImage image = makeBufferedImage(new StarIcon(), d.width, d.height); final PopupMenu popup = new PopupMenu(); final TrayIcon icon = new TrayIcon(image, "TRAY", popup); MenuItem item1 = new MenuItem("OPEN"); item1.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.setVisible(true); } }); MenuItem item2 = new MenuItem("EXIT"); item2.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tray.remove(icon); frame.dispose(); // frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); } }); popup.add(item1); popup.add(item2); try { tray.add(icon); } catch (AWTException e) { e.printStackTrace(); } }
private static void createAndShowGUI() { // Check the SystemTray support if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return; } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("logo.gif", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components MenuItem aboutItem = new MenuItem("About"); MenuItem exitItem = new MenuItem("Exit"); // Add components to popup menu popup.add(aboutItem); popup.addSeparator(); popup.add(exitItem); trayIcon.setPopupMenu(popup); trayIcon.setImageAutoSize(true); trayIcon.setToolTip("Geomar Wetterdaten"); try { tray.add(trayIcon); } catch (AWTException e) { System.out.println("TrayIcon could not be added."); return; } trayIcon.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray"); } }); aboutItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog( null, "Windgeschwindigkeit: " + weather.getWindspeed() + "m/s\n" + "Windrichtung: " + weather.getDirection() + "° " + weather.calcDir(weather.getDirection())); } }); exitItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); }
@SuppressWarnings("deprecation") public void addItem(MenuItem item) { // the current awt way of adding a separator appears to be adding an item with "-" as the label if ("-".equals(item.getLabel())) { addSeparator(); } else { item.addNotify(); jComponent.add(((SwingBaseMenuItemPeer<?, ?>) item.getPeer()).jComponent); } }
protected PopupMenu getRoadMenu(Road r) { PopupMenu menu = new PopupMenu(); PopupMenuListener pml = new RoadPopupListener(r, controller); MenuItem item = new MenuItem("Properties...", new MenuShortcut(KeyEvent.VK_ENTER)); item.addActionListener(pml); menu.add(item); return menu; }
protected PopupMenu getDrivelaneMenu(Drivelane l) { PopupMenu menu = new PopupMenu(); PopupMenuListener pml = new LanePopupListener(l, controller); MenuItem item = new MenuItem("Properties...", new MenuShortcut(KeyEvent.VK_ENTER)); item.addActionListener(pml); menu.add(item); return menu; }
@SuppressWarnings("deprecation") public SwingMenuPeer(SwingToolkit toolkit, Menu menu) { super(toolkit, menu, new JMenu()); int item_count = menu.getItemCount(); for (int i = 0; i < item_count; i++) { MenuItem menu_item = menu.getItem(i); menu_item.addNotify(); jComponent.add(((SwingMenuComponentPeer<?, ?>) menu_item.getPeer()).jComponent); } }
public void init() { final TrayIcon trayIcon; if (!SystemTray.isSupported()) { System.err.println("SystemTray is not supported"); return; } SystemTray tray = SystemTray.getSystemTray(); Image image = new ImageIcon(getClass().getResource("/threaded/ThreadedEshoServer/db_settings_32.png")) .getImage(); // ‘ормирование меню PopupMenu popup = new PopupMenu(); MenuItem exitItem = new MenuItem("Exit"); exitItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); popup.add(exitItem); trayIcon = new TrayIcon(image, "My server", popup); trayIcon.setImageAutoSize(true); trayIcon.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { trayIcon.displayMessage( "My server", "—ообщение по дабл клику", TrayIcon.MessageType.INFO); } }); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println("TrayIcon could not be added"); return; } Timer timer = new Timer( 10000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // trayIcon.displayMessage("Your messages:", // "я вывел это сообщение", TrayIcon.MessageType.INFO); } }); timer.start(); }
public CutAndPaste() { cut.addActionListener(new CutL()); copy.addActionListener(new CopyL()); paste.addActionListener(new PasteL()); edit.add(cut); edit.add(copy); edit.add(paste); mb.add(edit); setMenuBar(mb); add(text, BorderLayout.CENTER); }
public static synchronized void drawWhiteTextRect( MenuItem item, float x, float y, float w, float h) { Graphics2D g2 = item.menu.buff.g2; roundRect.setRoundRect(x, y, w, h, h / 3, h / 3); if (!item.isEnabled()) g2.setPaint(item.getStyle().getC("c.disabled")); else g2.setPaint(Color.white); g2.fill(roundRect); g2.setPaint(Color.black); g2.setStroke(new BasicStroke(item.getStyle().getF("f.strokeWeight"))); g2.draw(roundRect); }
/** * Method declaration * * @param f * @param m */ void addMenuItems(Menu f, String m[]) { for (int i = 0; i < m.length; i++) { MenuItem item = new MenuItem(m[i].substring(1)); char c = m[i].charAt(0); if (c != '-') { item.setShortcut(new MenuShortcut(c)); } item.addActionListener(this); f.add(item); } }
public static synchronized void drawSingleGradientRect( MenuItem item, float x, float y, float width, float height, float roundOff) { Menu menu = item.menu; MenuStyle style = item.getStyle(); roundRect.setRoundRect(x, y, width, height, roundOff, roundOff); Graphics2D g2 = menu.buff.g2; /* * Set the correct fill gradient */ if (item.isOpen()) { g2.setPaint(item.getStyle().getGradient(MenuItem.DOWN, y, y + height)); } else { g2.setPaint(item.getStyle().getGradient(MenuItem.OVER, y, y + height)); } /* * Only perform the fill if the mood is right. */ if (item.getState() != MenuItem.UP || item.isOpen()) { g2.fill(roundRect); } /* * Draw the rounded rectangle outline. */ if (item.getState() != MenuItem.UP || item.isOpen()) { drawRoundOutline(item, roundRect); } }
public void actionPerformed(ActionEvent evt) { String cmd = evt.getActionCommand(); ImageJ.setCommandName(cmd); MenuItem item = (MenuItem) evt.getSource(); MenuContainer parent = item.getParent(); if (parent instanceof PopupMenu) { for (int i = 0; i < nMacros; i++) { if (macroNames[i].equals("Popup Menu")) { new MacroRunner(pgm, macroStarts[i], "Popup Menu", cmd); return; } } } runMacro(cmd); }
/** 给组件添加监听事件 */ void setEvent() { System.out.println("设置菜单监听"); // 按键添加监听 bt0_HomePanel.addActionListener(new MyBtMenuListener()); bt1_SettingPanel.addActionListener(new MyBtMenuListener()); bt2_DrawwingPanel.addActionListener(new MyBtMenuListener()); bt3_InternetPanel.addActionListener(new MyBtMenuListener()); bt4_OtherPanel.addActionListener(new MyBtMenuListener()); // 菜单项监听 mi_0.addActionListener(new MyMenuItemsListener()); mi_1.addActionListener(new MyMenuItemsListener()); mi_2.addActionListener(new MyMenuItemsListener()); }
public void goTo(int where) { try { if (where < 1) { return; } if (where > db.getRecordCount()) { return; } db.gotoRecord(where); crl.setText("Record " + db.getCurrentRecordNumber()); delCB.setState(db.deleted()); Field f; LogicalField lf; Checkbox c; TextField t; int i; for (i = 1; i <= db.getFieldCount(); i++) { f = db.getField(i); if (f.isMemoField()) { } else if (f.getType() == 'L') { lf = (LogicalField) f; c = (Checkbox) fldObjects.elementAt(i - 1); c.setState(lf.getBoolean()); } else { t = (TextField) fldObjects.elementAt(i - 1); t.setText(f.get().trim()); } } Next.setEnabled(!(db.getCurrentRecordNumber() == db.getRecordCount())); nextRecord.setEnabled(!(db.getCurrentRecordNumber() == db.getRecordCount())); Prev.setEnabled(!(db.getCurrentRecordNumber() == 1)); prevRecord.setEnabled(!(db.getCurrentRecordNumber() == 1)); firstRecord.setEnabled(db.getRecordCount() > 0); lastRecord.setEnabled(db.getRecordCount() > 0); SBrecpos.setValues(db.getCurrentRecordNumber(), 1, 0, db.getRecordCount()); } // try catch (Exception e1) { System.out.println(e1); System.exit(2); } }
Timed() throws AWTException { // super("Trial by fire"); setLayout(new FlowLayout()); label.setFont( new Font( label.getFont().getName(), label.getFont().getStyle(), label.getFont().getSize() + 6)); Container content = getContentPane(); content.add(label, JLabel.CENTER); addMouseMotionListener(this); addMouseListener(this); javax.swing.Timer t = new javax.swing.Timer(1000, this); setUndecorated(true); com.sun.awt.AWTUtilities.setWindowOpacity(this, 0.6f); // system tray mItem1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); popup.add(mItem1); systray.add(tray); tray.setImageAutoSize(true); t.start(); }
public void actionPerformed(ActionEvent arg0) { if (form.getFrame().isVisible()) { form.getFrame().setVisible(false); putValue(Action.NAME, SHOW_NAME); putValue(SHORT_DESCRIPTION, SHOW_DESC); putValue(SMALL_ICON, SHOW_ICON); menuItem.setLabel(SHOW_NAME); } else { form.getFrame().setVisible(true); putValue(Action.NAME, HIDE_NAME); putValue(SHORT_DESCRIPTION, HIDE_DESC); putValue(SMALL_ICON, HIDE_ICON); menuItem.setLabel(HIDE_NAME); } }
public static synchronized void drawDoubleGradientRect( MenuItem item, float x, float y, float width, float height) { PGraphicsJava2D buff = item.menu.buff; MenuStyle style = item.getStyle(); Menu menu = item.menu; float ro = style.getF("f.roundOff"); roundRect.setRoundRect(x, y, width, height, ro, ro); /* * Draw the first gradient: a full-height gradient. */ buff.g2.setPaint(style.getGradient(MenuItem.UP, x, y, x, y + height)); buff.g2.fill(roundRect); /* * Draw a translucent gradient on top of the first, starting halfway and * going to the bottom. */ Composite oldC = buff.g2.getComposite(); AlphaComposite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f * menu.alpha); buff.g2.setComposite(c); buff.g2.setPaint(style.getGradient(MenuItem.UP, x, y + height, x, y + height / 3)); buff.g2.fillRect((int) x, (int) (y + height / 2), (int) width, (int) height / 2); buff.g2.setComposite(oldC); /* * Finally, draw the stroke on top of everything. */ drawRoundOutline(item, roundRect); }
public static synchronized void drawBlankRect(MenuItem item, float x, float y, float w, float h) { MenuItem menu = item.menu; MenuStyle style = item.getStyle(); roundRect.setRoundRect(x, y, w, h, 0, 0); drawRoundOutline(item, roundRect); }