public Layout(ArrayList<Car> idata) { this.setSize(600, 400); this.data = idata; /** Input modulok dinicializálása* */ up = new JPanel(); down = new JPanel(); menuFile = new JMenu("File"); menuItemAdd = new JMenuItem("Add"); menuItemLoad = new JMenuItem("Load"); menuItemSave = new JMenuItem("Save"); menuItemChoose = new JMenuItem("Choose"); menuBar = new JMenuBar(); /** Menu Betöltések* */ menuBar.add(menuFile); menuFile.add(menuItemAdd); menuFile.add(menuItemLoad); menuFile.add(menuItemSave); menuFile.add(menuItemChoose); /** Table Betoltes* */ String[] headers = {"id", "tipus", "szin", "motor"}; dataTable = new CustomTable(data, headers); /** Listener hozzáadása a gombokhoz */ ButtonListener bl = new ButtonListener(); /** Listener hozzáadása menükhöz* */ menuItemAdd.setActionCommand("add"); menuItemAdd.addActionListener(bl); menuItemSave.setActionCommand("save"); menuItemSave.addActionListener(bl); menuItemLoad.setActionCommand("load"); menuItemLoad.addActionListener(bl); menuItemChoose.setActionCommand("browse"); menuItemChoose.addActionListener(bl); /** Felrajzolas* */ down.add(dataTable); this.add(up, SpringLayout.NORTH); this.add(down, BorderLayout.CENTER); this.setJMenuBar(menuBar); this.pack(); this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); this.setTitle("Register"); this.pack(); }
public void populateMenu(JMenu menu, int flags) { if (flags == (Plugin.MENU_TOOLS | Plugin.MENU_MID)) { Sketch sketch = editor.getSketch(); JMenuItem item = new JMenu("Program Bootloader"); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { run(); } }); menu.add(item); PropertyFile props = sketch.mergeAllProperties(); String blProgs = props.get("bootloader.upload"); if (blProgs == null) { JMenuItem sub = new JMenuItem("No bootloader programmer defined!"); item.add(sub); return; } String[] progs = blProgs.split("::"); for (String prog : progs) { JMenuItem sub = new JMenuItem(sketch.parseString(props.get("upload." + prog + ".name"))); sub.setActionCommand(prog); sub.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doProgram(e.getActionCommand()); } }); item.add(sub); } } }
/** * This is the hook through which all menu items are created. It registers the result with the * menuitem hashtable so that it can be fetched with getMenuItem(). * * @see #getMenuItem */ protected JMenuItem createMenuItem(String cmd) { JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix)); URL url = getResource(cmd + imageSuffix); if (url != null) { mi.setHorizontalTextPosition(JButton.RIGHT); mi.setIcon(new ImageIcon(url)); } String astr = getResourceString(cmd + actionSuffix); if (astr == null) { astr = cmd; } mi.setActionCommand(astr); Action myaction = getAction(astr); // if this is a known action if (myaction != null) { mi.addActionListener(myaction); myaction.addPropertyChangeListener(createActionChangeListener(mi)); // System.out.println("myaction not null: astr:"+astr+" enabled:"+myaction.isEnabled()); mi.setEnabled(myaction.isEnabled()); } else { System.err.println("Error:TextViewer: createMenuItem: myaction is null: astr:" + astr); // causes the item to be greyed out mi.setEnabled(false); } menuItems.put(cmd, mi); return mi; }
/** When a new set of saved statements come in, refresh the menu of saved statements. */ private void refreshSaveMenu() { ArrayList list; // first, delete what's already there for (; ; ) { Component comp = popup.getComponent(1); if (!(comp instanceof JMenuItem)) break; JMenuItem item = (JMenuItem) comp; if (item.getActionCommand().startsWith("save:")) popup.remove(1); else break; } StatementHistory history; history = sshare.statementHistory(); // now insert the new list of saved statements list = history.getNamedStatementList(); Color bgColor = Util.getBgColor(); for (int i = 0; i < list.size(); i++) { ArrayList nameNlabel = (ArrayList) list.get(i); JMenuItem item = new JMenuItem(" " + (String) nameNlabel.get(1)); item.setActionCommand("save:" + (String) nameNlabel.get(0)); popup.add(item, 1); // item.setBackground(bgColor); item.addActionListener(popActionListener); } } // refreshSaveMenu()
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) + "..."; } JMenuItem item = new JMenuItem(s); item.setActionCommand("#" + iRecent); item.addActionListener(this); mRecent.insert(item, iRecent); iRecent = (iRecent + 1) % iMaxRecent; }
// 构造函数 public MyTankGame8() { // mp=new MyPanel(); // 启动MyPanel线程 // Thread t=new Thread(mp); // t.start(); // this.add(mp); // 创建菜单及菜单选项 jmb = new JMenuBar(); jm1 = new JMenu("游戏(G)"); // 设置助记符 jm1.setMnemonic('G'); jmi1 = new JMenuItem("开始新游戏(N)"); jmi2 = new JMenuItem("退出游戏(E)"); jmi3 = new JMenuItem("存盘退出(C)"); jmi4 = new JMenuItem("接上局玩(S)"); jmi3.addActionListener(this); jmi3.setActionCommand("saveExit"); jmi2.addActionListener(this); jmi2.setActionCommand("exit"); jmi4.addActionListener(this); jmi4.setActionCommand("continue"); jmi2.setMnemonic('E'); jmi1.setMnemonic('N'); // 对jmi1响应 jmi1.addActionListener(this); jmi1.setActionCommand("new game"); jm1.add(jmi1); jm1.add(jmi2); jmb.add(jm1); jm1.add(jmi3); jm1.add(jmi4); msp = new MyStartPanel(); Thread t = new Thread(msp); t.start(); this.setJMenuBar(jmb); this.add(msp); this.setSize(600, 500); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
public CBPopupMenu() { JMenuItem item; item = new JMenuItem("Standard Gradient"); item.setActionCommand("standard"); item.addActionListener(this); add(item); item = new JMenuItem("Invert map"); item.setActionCommand("invert"); item.addActionListener(this); add(item); item = new JMenuItem("Rainbow gradient"); item.setActionCommand("rainbow"); item.addActionListener(this); add(item); item = new JMenuItem("Greyscale gradient"); item.setActionCommand("grey"); item.addActionListener(this); add(item); item = new JMenuItem("Swap Background Black/White"); item.setActionCommand("swapBackground"); item.addActionListener(this); add(item); }
JMenuItem getItem() { JMenuItem i; if (null == cmd) { i = new JMenu(name); for (MenuElement e : submenu) { i.add(e.getItem()); } } else { i = new JMenuItem(cmd.name()); i.setActionCommand(cmd.name()); i.addActionListener(menuListener); } return i; }
/** This is the hook through which all menu items are created. */ protected JMenuItem createMenuItem(String cmd) { JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix)); URL url = getResource(cmd + imageSuffix); if (url != null) { mi.setHorizontalTextPosition(JButton.RIGHT); mi.setIcon(new ImageIcon(url)); } String astr = getProperty(cmd + actionSuffix); if (astr == null) { astr = cmd; } mi.setActionCommand(astr); Action a = getAction(astr); if (a != null) { mi.addActionListener(a); a.addPropertyChangeListener(createActionChangeListener(mi)); mi.setEnabled(a.isEnabled()); } else { mi.setEnabled(false); } return mi; }
public void mouseClicked(MouseEvent evt) { int btn = evt.getButton(); if (btn == MouseEvent.BUTTON3) { JPopupMenu helpMenu = new JPopupMenu(); String helpLabel = Util.getLabel("CSHMenu"); JMenuItem helpMenuItem = new JMenuItem(helpLabel); helpMenuItem.setActionCommand("help"); helpMenu.add(helpMenuItem); ActionListener alMenuItem = new ActionListener() { public void actionPerformed(ActionEvent e) { String topic = ""; try { JComponent c1 = (JComponent) tabbedPane.getSelectedComponent(); // This component should contain the following embedded items. // We want m_helplink out of the top VGroup. // PushpinObj // XMLToolPanel // JScrollpane // JViewport // JPanel // VGroup // Work down to the VGroup, checking for class type along // the way. if (c1 instanceof PushpinObj) { Component c2[] = c1.getComponents(); int cnt; for (cnt = 0; cnt < c2.length; cnt++) { // The PushpinObj can have multiple items, find the one we want if (c2[cnt] instanceof XMLToolPanel) break; } if (cnt < c2.length && c2[cnt] instanceof XMLToolPanel) { Component c3[] = ((JComponent) c2[cnt]).getComponents(); if (c3[0] instanceof JScrollPane) { Component c4[] = ((JComponent) c3[0]).getComponents(); if (c4[0] instanceof JViewport) { Component c5[] = ((JComponent) c4[0]).getComponents(); if (c5[0] instanceof JPanel) { Component c6[] = ((JComponent) c5[0]).getComponents(); if (c6[0] instanceof VGroup) { // Get the helplink info from the VGroup topic = ((VGroup) c6[0]).getAttribute(VObjDef.HELPLINK); } } } } } } // If no helplink found, try the Tab's name if (topic == null || topic.length() == 0) { topic = c1.getName(); if (topic.equals("Locator")) topic = getLocatorName(); topic = topic.replace(" ", "_"); } } catch (Exception ex) { } // Get the ID and display the help content CSH_Util.displayCSHelp(topic); } }; helpMenuItem.addActionListener(alMenuItem); Point pt = evt.getPoint(); helpMenu.show(VTabbedToolPanel.this, (int) pt.getX(), (int) pt.getY()); } }
private JMenuItem makeMenuItem(String s) { JMenuItem item = new JMenuItem(s); item.setActionCommand(s); item.addActionListener(this); return item; }
public static void makeMenuBar(JFrame frame, final AirspaceBuilderController controller) { JMenuBar menuBar = new JMenuBar(); final JCheckBoxMenuItem resizeNewShapesItem; final JCheckBoxMenuItem enableEditItem; JMenu menu = new JMenu("File"); { JMenuItem item = new JMenuItem("Open..."); item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.setActionCommand(OPEN); item.addActionListener(controller); menu.add(item); item = new JMenuItem("Open URL..."); item.setActionCommand(OPEN_URL); item.addActionListener(controller); menu.add(item); item = new JMenuItem("Save..."); item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.setActionCommand(SAVE); item.addActionListener(controller); menu.add(item); menu.addSeparator(); item = new JMenuItem("Load Demo Shapes"); item.setActionCommand(OPEN_DEMO_AIRSPACES); item.addActionListener(controller); menu.add(item); } menuBar.add(menu); menu = new JMenu("Shape"); { JMenu subMenu = new JMenu("New"); for (final AirspaceFactory factory : defaultAirspaceFactories) { JMenuItem item = new JMenuItem(factory.toString()); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.createNewEntry(factory); } }); subMenu.add(item); } menu.add(subMenu); resizeNewShapesItem = new JCheckBoxMenuItem("Fit new shapes to viewport"); resizeNewShapesItem.setActionCommand(SIZE_NEW_SHAPES_TO_VIEWPORT); resizeNewShapesItem.addActionListener(controller); resizeNewShapesItem.setState(controller.isResizeNewShapesToViewport()); menu.add(resizeNewShapesItem); enableEditItem = new JCheckBoxMenuItem("Enable shape editing"); enableEditItem.setActionCommand(ENABLE_EDIT); enableEditItem.addActionListener(controller); enableEditItem.setState(controller.isEnableEdit()); menu.add(enableEditItem); } menuBar.add(menu); menu = new JMenu("Selection"); { JMenuItem item = new JMenuItem("Deselect"); item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.setActionCommand(CLEAR_SELECTION); item.addActionListener(controller); menu.add(item); item = new JMenuItem("Delete"); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); item.setActionCommand(REMOVE_SELECTED); item.addActionListener(controller); menu.add(item); } menuBar.add(menu); frame.setJMenuBar(menuBar); controller.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if (SIZE_NEW_SHAPES_TO_VIEWPORT.equals((e.getPropertyName()))) { resizeNewShapesItem.setSelected(controller.isResizeNewShapesToViewport()); } else if (ENABLE_EDIT.equals(e.getPropertyName())) { enableEditItem.setSelected(controller.isEnableEdit()); } } }); }
public PuzzelHA() { window = new JFrame("PuzzelHA"); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // window.setSize(800, 600); // -----------------Menü erstellen--------------------------------------- JMenuBar menu = new JMenuBar(); menu.setBorder(new LineBorder(Color.BLACK, 1)); JMenu spiel = new JMenu("Spiel"); JMenuItem reset = new JMenuItem("Reset"); reset.addActionListener(this); reset.setActionCommand("reset"); spiel.add(reset); JMenu ansicht = new JMenu("Ansicht"); JMenu bild = new JMenu("BildNr."); ansicht.add(bild); ButtonGroup bg1 = new ButtonGroup(); for (int j = 1; j <= bilder.size(); j++) { JRadioButtonMenuItem bn = new JRadioButtonMenuItem("" + j); bn.setName("" + j); bn.setActionCommand("b"); bn.addActionListener(this); bg1.add(bn); bild.add(bn); } // --------------RadioButtons für Puzzelgröße---------------------------------- JMenu pg = new JMenu("Puzzelgröße"); ansicht.add(pg); ButtonGroup bg2 = new ButtonGroup(); JRadioButtonMenuItem pgb1 = new JRadioButtonMenuItem("2x3"); pgb1.setActionCommand("g1"); pgb1.addActionListener(this); bg2.add(pgb1); pg.add(pgb1); for (int i = 2; i <= 4; i++) { JRadioButtonMenuItem pgb = new JRadioButtonMenuItem("" + (i * 2) + "x" + (i * 2 - 1)); pgb.setActionCommand("g" + i); pgb.addActionListener(this); bg2.add(pgb); pg.add(pgb); } JMenu help = new JMenu("?"); JMenuItem info = new JMenuItem("Info"); info.addActionListener(this); info.setActionCommand("?"); help.add(info); menu.add(spiel); menu.add(ansicht); menu.add(help); window.add(menu); window.setJMenuBar(menu); // ---------------- Menü END------------------------------------- baueButton(); window.setResizable(false); window.setLocationRelativeTo(null); window.pack(); window.setVisible(true); }
public AutoFocusator() { super(new BorderLayout()); taskList = new TaskList(); Task task0 = new Task("Use right click to change the states of the tasks."); taskList.add(task0); Task task1 = new Task("Just play araound with this small app."); taskList.add(task1); Task task2 = new Task("Check http://sourceforge.net/projects/autofocusator/"); taskList.add(task2); // task1.setState(State.crossed); // task0.setState(State.dismissed); table = new JTable(taskList); table.setPreferredScrollableViewportSize(new Dimension(500, 700)); table.setFillsViewportHeight(true); table.getColumnModel().getColumn(0).setPreferredWidth(300); table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); table.setRowSelectionAllowed(true); table.getColumnModel().getColumn(0).setCellRenderer(new TaskRenderer()); // TableCellRenderer renderer = table.getColumnModel().getColumn(0).getCellRenderer(); // double height = ((TaskRenderer)renderer).getRendererHeight(); // @todo: The height should be set dependent on the content table.setRowHeight(28); table.getModel().addTableModelListener(this); toolBar = new JToolBar("Autofocusator - Toolbar"); JButton buttonAddTask = new JButton("Add a Task", new ImageIcon(loadPics("res/list-add.png"))); buttonAddTask.setActionCommand("addTask"); buttonAddTask.addActionListener(this); toolBar.add(buttonAddTask); JButton buttonDeleteTask = new JButton("Delete a Task", new ImageIcon(loadPics("res/list-remove.png"))); buttonDeleteTask.setActionCommand("deleteTask"); buttonDeleteTask.addActionListener(this); toolBar.add(buttonDeleteTask); JButton buttonSave = new JButton("Save", new ImageIcon(loadPics("res/document-save-as.png"))); buttonSave.setActionCommand("save"); buttonSave.addActionListener(this); toolBar.add(buttonSave); JButton buttonOpen = new JButton("open", new ImageIcon(loadPics("res/document-open.png"))); buttonOpen.setActionCommand("open"); buttonOpen.addActionListener(this); toolBar.add(buttonOpen); add(toolBar, BorderLayout.NORTH); contextMenu = new JPopupMenu(); JMenuItem contextMenuItem; contextMenuItem = new JMenuItem("delete Task"); contextMenuItem.addActionListener(this); contextMenuItem.setActionCommand("deleteTask"); contextMenu.add(contextMenuItem); contextMenuItem = new JMenuItem("add Task"); contextMenuItem.addActionListener(this); contextMenuItem.setActionCommand("addTask"); contextMenu.add(contextMenuItem); contextMenu.addSeparator(); contextMenuItem = new JMenuItem("cross"); contextMenuItem.addActionListener(this); contextMenuItem.setActionCommand("cross"); contextMenu.add(contextMenuItem); contextMenuItem = new JMenuItem("dismiss"); contextMenuItem.addActionListener(this); contextMenuItem.setActionCommand("dismiss"); contextMenu.add(contextMenuItem); contextMenuItem = new JMenuItem("worked on"); contextMenuItem.addActionListener(this); contextMenuItem.setActionCommand("workedOn"); contextMenu.add(contextMenuItem); fileChooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("XML File", "xml"); fileChooser.addChoosableFileFilter(filter); table.addMouseListener(this); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane, BorderLayout.CENTER); }
public void fillPopupMenu() { JMenuItem item; TextImageIcon textIcon; StatementHistory history; int rowCount = 0; int numRows = 0; Insets margin = new Insets(0, 0, 0, 0); // Get the font defined in the displayOptions panel for menus Font ft = DisplayOptions.getFont("Menu1"); // We need a fairly small font, so make it 2 smaller. int size = ft.getSize(); // If larger than 12, subtract 2 if (size > 12) size -= 2; Font font = DisplayOptions.getFont(ft.getName(), ft.getStyle(), size); // This flag is used so that we only fill the menu when needed if (menuAlreadyFilled) return; menuAlreadyFilled = true; history = sshare.statementHistory(); ArrayList list = history.getNamedStatementList(); Color bgColor = Util.getBgColor(); // Only show the Saved Statements section if there are some. if (list != null && list.size() != 0) { item = popup.add("Saved Statements"); rowCount++; // item.setForeground(Color.blue); // item.setBackground(bgColor); item.setFont(font); item.setMargin(margin); popup.add(item); for (int i = 0; i < list.size(); i++) { ArrayList nameNlabel = (ArrayList) list.get(i); // first item in nameNlabel is name and second is label item = popup.add(" " + (String) nameNlabel.get(1)); rowCount++; item.setActionCommand("save:" + (String) nameNlabel.get(0)); // item.setBackground(bgColor); item.addActionListener(popActionListener); item.setFont(font); item.setMargin(margin); } } // the rest of menu (return object types, statement types, etc.) ShufflerService shufflerService = sshare.shufflerService(); ArrayList objTypes = shufflerService.getAllMenuObjectTypes(); for (int i = 0; i < objTypes.size(); i++) { String objType = (String) objTypes.get(i); // Do not display menu for DB_AVAIL_SUB_TYPES if (objType.equals(Shuf.DB_AVAIL_SUB_TYPES)) continue; // addSeparator looks bad using GridLayout because it creates rows // and columns which are all equal in size. It cannot have a row // with a separator which is a different height than the other // rectangles it creates. So just use dashes. item = popup.add(separator); item.setFont(font); item.setMargin(margin); rowCount++; item = popup.add(shufflerService.getCategoryLabel(objType)); rowCount++; // item.setForeground(Color.blue); item.setActionCommand("title:" + objType); // item.setBackground(bgColor); item.addActionListener(popActionListener); item.setFont(font); item.setMargin(margin); ArrayList menuStrings = shufflerService.getmenuStringsThisObj(objType); // If current rowCount plus the next section size is too big, // specify the numRows to the current value of rowCount -1. // That is, put this next section in a new column. // 47 is emperical number of rows to fit 90% full screen. if (numRows == 0 && rowCount - 1 + menuStrings.size() > 44) { numRows = rowCount - 2; } for (int j = 0; j < menuStrings.size(); j++) { String menuString = (String) menuStrings.get(j); item = popup.add(" " + menuString); rowCount++; item.setActionCommand("command:" + objType + "/" + menuString); // item.setBackground(bgColor); item.addActionListener(popActionListener); item.setFont(font); item.setMargin(margin); } // The spotter menu changes dynamically when // the list of saved statements changes. history.addStatementListener( new StatementAdapter() { public void saveListChanged() { refreshSaveMenu(); } }); } if (numRows == 0) numRows = rowCount; GridLayoutCol lm = new GridLayoutCol(numRows, 0); popup.setLayout(lm); }