List of usage examples for javax.swing JMenuBar add
public JMenu add(JMenu c)
From source file:com.imag.nespros.gui.plugin.GraphEditor.java
private static void initMenu() { JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Make Image") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); }/*from w w w. j av a 2 s. co m*/ } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); menu.add(new AbstractAction("Save topology") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { demo.save(file); frame.setTitle(file.getName()); } catch (IOException ex) { Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex); } } } }); menu.add(new AbstractAction("Load topology") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showOpenDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { //EPGraph.getInstance().resetMapping(); simu.resetMapping(); demo.load(file); frame.setTitle("Simulator - " + file.getName()); } catch (FileNotFoundException ex) { Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex); } } } }); JMenu menu2 = new JMenu("View"); menu2.add(new AbstractAction("Layout") { @Override public void actionPerformed(ActionEvent e) { Layout l = new CircleLayout<Device, ComLink>(Topology.getInstance().getGraph()); l.setInitializer(vv.getGraphLayout()); l.setSize(vv.getSize()); LayoutTransition<Device, ComLink> lt = new LayoutTransition<>(vv, vv.getGraphLayout(), l); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } }); menu2.add(new AbstractAction("Event Composition Networks") { @Override public void actionPerformed(ActionEvent e) { showEPGraph(EPGraph.getInstance().getGraph()); } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); menuBar.add(menu2); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); buildEPGraphs(); showEPGraph(EPGraph.getInstance().getGraph()); }
From source file:levelBuilder.DialogMaker.java
/** * Various routines necessary for displaying graph. */// ww w . j a va 2s . c o m private static void displayGraph() { JFrame frame = new JFrame("Dialog Maker"); layout = new KKLayout<DialogNode, Double>(g); VisualizationViewer<DialogNode, Double> vv = new VisualizationViewer<DialogNode, Double>(layout); layout.setSize(new Dimension(windowWidth, windowHeight)); vv.setPreferredSize(new Dimension(windowWidth, windowHeight)); //Changes fields in node properties window when a node is selected pickedState = vv.getPickedVertexState(); pickedState.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { Object subject = e.getItem(); if (subject instanceof DialogNode) { selectedNode = (DialogNode) subject; textField.setText(selectedNode.getText()); npcBox.setSelected(selectedNode.getIsNPC()); String working = ""; for (int c = 0; c < selectedNode.getChildren().length; c++) { if (c == 0) working += selectedNode.getChildren()[c].getText(); else working += "," + selectedNode.getChildren()[c].getText(); } if (working.equals("null")) working = ""; childrenField.setText(working.replace("]", "").replace("[", "")); working = Arrays.toString(selectedNode.getProbSets().get(strategy)); if (working.equals("null")) working = ""; probSetField.setText(working.replace("]", "").replace("[", "").replace(" ", "")); } } }); //Colors vertices according to 'initial', 'end', or 'middle' status. vv.getRenderContext().setVertexFillPaintTransformer(new Transformer<DialogNode, Paint>() { @Override public Paint transform(DialogNode n) { if (n.getText().equals("initial")) return new Color(100, 255, 100); if (n.getChildren().length == 0) return new Color(255, 100, 100); return new Color(100, 100, 255); } }); //Labels vertices with node text. vv.getRenderContext().setVertexLabelTransformer(new Transformer<DialogNode, String>() { @Override public String transform(DialogNode n) { return n.getText().split(" ")[0]; } }); //Draws shape of vertices according to player or non-player status. vv.getRenderContext().setVertexShapeTransformer(new Transformer<DialogNode, Shape>() { @Override public Shape transform(DialogNode n) { if (n.getIsNPC()) return new Rectangle(-15, -15, 30, 30); else return new Ellipse2D.Double(-15.0, -15.0, 30.0, 30.0); } }); //Labels edges with probability of child being selected under the current strategy. vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Double, String>() { @Override public String transform(Double e) { DialogNode source = g.getSource(e); if (source.getProbSets().size() > 0) for (int c = 0; c < source.getChildren().length; c++) if (source.getChildren()[c].equals(g.getDest(e))) { if (source.getProbSets().get(strategy) != null) return Double.toString(source.getProbSets().get(strategy)[c]); else //If node does not have probSet for that strategy, default to strategy 0. return Double.toString(source.getProbSets().get(0)[c]); } return null; } }); vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); //Routines for editing mode. EditingModalGraphMouse<DialogNode, Double> gm = new EditingModalGraphMouse<DialogNode, Double>( vv.getRenderContext(), //Runs when a new node is created. new Factory<DialogNode>() { @Override public DialogNode create() { DialogNode n = new DialogNode(isNPCBoxChecked, textField.getText(), new ArrayList<double[]>(), new DialogNode[0]); dg.addNode(n); return n; } }, //Runs when a new edge is created. new Factory<Double>() { @Override public Double create() { addedEdgeID = Math.random(); return addedEdgeID; } }); vv.setGraphMouse(gm); //Frame and mode menu. JMenuBar menuBar = new JMenuBar(); JMenu modeMenu = gm.getModeMenu(); modeMenu.setText("Mouse Mode"); modeMenu.setIcon(null); modeMenu.setPreferredSize(new Dimension(100, 20)); menuBar.add(modeMenu); frame.setJMenuBar(menuBar); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(vv); frame.pack(); frame.setVisible(true); // //Sets position of each node. // for (DialogNode n : nodeMap.values()) { // Point2D.Double point = new Point2D.Double(n.getX(), n.getY()); // if (point.x != 0.0 && point.y != 0.0) // layout.setLocation(n, point); // } }
From source file:Main.java
public JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); menuBar.add(createMenu("Menu 1")); menuBar.add(createMenu("Menu 2")); menuBar.add(Box.createHorizontalGlue()); menuBar.add(createMenu("Menu 3")); return menuBar; }
From source file:RootExample3.java
public RootExample3() { super("RootPane Menu Demo"); setSize(220, 100);//w w w .j a v a 2 s .c o m setDefaultCloseOperation(EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); bar.add(menu); menu.add("Open"); menu.add("Close"); setJMenuBar(bar); getContentPane().add(new JButton("Hello World")); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); bar.add(menu); menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit"), 0); setJMenuBar(bar);/*from w ww . j a va 2 s . c om*/ add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); bar.add(menu); menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar);//from w ww . j a va 2 s . c o m add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); }
From source file:MenuSeparator.java
public MenuSeparator() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); bar.add(menu); menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar);/*from w ww . j ava 2 s .c om*/ getContentPane().add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); }
From source file:Main.java
public void build() { setSize(600, 600);//from ww w.j av a 2s . com JTextPane textPane = new JTextPane(); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(300, 300)); JTextArea changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); JPanel statusPane = new JPanel(new GridLayout(1, 1)); JLabel caretListenerLabel = new JLabel("Caret Status"); statusPane.add(caretListenerLabel); JToolBar toolBar = new JToolBar(); toolBar.add(new JButton("Btn1")); toolBar.add(new JButton("Btn2")); toolBar.add(new JButton("Btn3")); toolBar.add(new JButton("Btn4")); getContentPane().add(toolBar, BorderLayout.PAGE_START); getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); JMenu editMenu = new JMenu("test"); JMenu styleMenu = new JMenu("test"); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); }
From source file:RootExample3.java
public RootExample3() { super("RootPane Menu Demo"); setSize(220, 100);//from w w w . ja va 2 s. com setDefaultCloseOperation(EXIT_ON_CLOSE); // Create a menu bar JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); bar.add(menu); menu.add("Open"); menu.add("Close"); setJMenuBar(bar); // Add a button to the content pane getContentPane().add(new JButton("Hello World")); }
From source file:Main.java
public Main() { int MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); KeyStroke exitKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, MASK); this.setDefaultCloseOperation(EXIT_ON_CLOSE); JMenu fileMenu = new JMenu("File"); JMenuItem fileExit = new JMenuItem(exitAction); fileMenu.add(fileExit);//from w ww . j a v a 2 s.c om JMenuBar menu = new JMenuBar(); menu.add(fileMenu); JDialog d = new JDialog(this, "Dialog"); JPanel p = new JPanel(); p.getInputMap().put(exitKey, exitName); p.getActionMap().put(exitName, exitAction); p.add(new JButton(exitAction)); d.add(p); d.pack(); d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setJMenuBar(menu); this.pack(); this.setSize(new Dimension(320, 240)); this.setVisible(true); d.setLocation(this.getRootPane().getContentPane().getLocationOnScreen()); d.setVisible(true); }